mit diesem kleinen Snippet, kann man sich den Pfad für den AllUsers Desktop sowie All Users Startmenü Pfad anhand der OS Version ausgeben lassen
using System;
namespace Framework
{
class SpecialEnvironment
{
public enum AllUsers : int
{
Desktop = 0,
Startmenue
}
public static string GetSpecialEnvironmentPath(AllUsers location)
{
string result = "";
switch (location)
{
case AllUsers.Desktop:
if (Environment.OSVersion.Version.Major > 4 && Environment.OSVersion.Version.Minor > 1)
result = Path.Combine(Environment.GetEnvironmentVariable("PUBLIC"), "Desktop");
else
result = Path.Combine(Environment.GetEnvironmentVariable("ALLUSERSPROFILE"), "Desktop");
break;
case AllUsers.Startmenue:
if (Environment.OSVersion.Version.Major > 4 && Environment.OSVersion.Version.Minor > 1)
result = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMDATA"), @"Microsoft\Windows\Start Menu");
else
result = Path.Combine(Environment.GetEnvironmentVariable("ALLUSERSPROFILE"), "Startmenü");
break;
default:
result = "";
break;
}
return result;
}
}
}
2 Kommentare zum Snippet