私は現在C#プロジェクトに取り組んでいます。ソフトウェアをより良く開発するために、ユーザーの統計を収集したいと思います。私はC#の機能を使用していますが、OS名はMicrosoftWindowsNTEnvironment.OS
のようなものとしてしか表示されません
取得できるようにしたいのは、OSの実際の既知の名前(それがそうであるかどうかWindows XP, Windows Vista or Windows 7
など)です。
これは可能ですか?
私は現在C#プロジェクトに取り組んでいます。ソフトウェアをより良く開発するために、ユーザーの統計を収集したいと思います。私はC#の機能を使用していますが、OS名はMicrosoftWindowsNTEnvironment.OS
のようなものとしてしか表示されません
取得できるようにしたいのは、OSの実際の既知の名前(それがそうであるかどうかWindows XP, Windows Vista or Windows 7
など)です。
これは可能ですか?
の参照とusingステートメントを追加しSystem.Management
、次に:
public static string GetOSFriendlyName()
{
string result = string.Empty;
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem");
foreach (ManagementObject os in searcher.Get())
{
result = os["Caption"].ToString();
break;
}
return result;
}
ローカルで使用する場合は、WMIを避けるようにしてください。非常に便利ですが、パフォーマンスの面で高額な費用がかかります。怠惰税を考えてください!
レジストリに関するKashishの回答は、すべてのシステムで機能するわけではありません。以下のコードには、サービスパックが含まれている必要があります。
public string HKLM_GetString(string path, string key)
{
try
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(path);
if (rk == null) return "";
return (string)rk.GetValue(key);
}
catch { return ""; }
}
public string FriendlyName()
{
string ProductName = HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName");
string CSDVersion = HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CSDVersion");
if (ProductName != "")
{
return (ProductName.StartsWith("Microsoft") ? "" : "Microsoft ") + ProductName +
(CSDVersion != "" ? " " + CSDVersion : "");
}
return "";
}
Microsoft.VisualBasicに.NET参照を追加します。次に、電話します。
new Microsoft.VisualBasic.Devices.ComputerInfo().OSFullName
MSDNから:
このプロパティは、Windows Management Instrumentation(WMI)がコンピューターにインストールされている場合、オペレーティングシステム名に関する詳細情報を返します。それ以外の場合、このプロパティはプロパティと同じ文字列を返します
My.Computer.Info.OSPlatform
。これは、WMIが提供できる情報よりも詳細な情報を提供しません。WMIが提供できる情報よりも情報が少なくなります。
String subKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion";
RegistryKey key = Registry.LocalMachine;
RegistryKey skey = key.OpenSubKey(subKey);
Console.WriteLine("OS Name: {0}", skey.GetValue("ProductName"));
これがお役に立てば幸いです
System.OperatingSystem osInfo = System.Environment.OSVersion;
public int OStype()
{
int os = 0;
IEnumerable<string> list64 = Directory.GetDirectories(Environment.GetEnvironmentVariable("SystemRoot")).Where(s => s.Equals(@"C:\Windows\SysWOW64"));
IEnumerable<string> list32 = Directory.GetDirectories(Environment.GetEnvironmentVariable("SystemRoot")).Where(s => s.Equals(@"C:\Windows\System32"));
if (list32.Count() > 0)
{
os = 32;
if (list64.Count() > 0)
os = 64;
}
return os;
}
string text = (string)Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion").GetValue("ProductName");
このコードは、この「Windows8.1Pro」のような完全なOS名を取得します