似乎"版本"参考Windows用于不同的事情。例如,Windows 10"周年纪念更新"标有"版本1607"由Microsoft(例如here)。但是,如果我试图获得"版本" (在安装了周年纪念更新的PC上)使用以下代码,不会返回任何看起来像" 1607"。
// Get Version details
Version ver = os.Version;
Console.WriteLine("Major version: " + ver.Major);
Console.WriteLine("Major Revision: " + ver.MajorRevision);
Console.WriteLine("Minor version: " + ver.Minor);
Console.WriteLine("Minor Revision: " + ver.MinorRevision);
Console.WriteLine("Build: " + ver.Build);
我明白了:
Major version: 6
Major Revision: 0
Minor version: 2
Minor Revision: 0
Build: 9200
如何获得Windows 10"版本"如在"版本1607"?
谢谢!
答案 0 :(得分:22)
根据MSDN official link,每个Windows版本都有特定的版本号。在dot net中,可以使用Environment.OSVersion对象读取它。
Console.WriteLine("OSVersion: {0}", Environment.OSVersion);
//output: OSVersion: Microsoft Windows NT 6.2.9200.0
您正在寻找的是ReleaseID而不是Windows版本。 这可以从注册表项中读取:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ReleaseId
using Microsoft.Win32;
string releaseId = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "").ToString();
Console.WriteLine(releaseId);
答案 1 :(得分:2)
exports.observeComments = functions.database.ref('/comments/{postId}/{commentId}')
.onCreate((snapshot, context) => {
var postId = context.params.postId
var commentId = context.params.commentId
console.log('Post: ' + postId + ' has a new comment: ' + commentId);
return admin.database().ref('/posts/' + postId).once('value', snapshot => {
var postsId = snapshot.val();
return admin.database().ref('/comments/{postId}' + commentId);
var commentsId = snapshot.val();
var payload = {
notification: {
body: commentId.uid + 'is going to your event.',
sound: 'default'
},
data: {
commentId: text
}
}
//Don't know who to send it to.
admin.messaging().sendToDevice(userGoing.fcmToken, payload)
.then(response => {
console.log("Successfully sent message:", response);
}).catch(function(error) {
console.log("Error sending message:", error)
})
})
})
使用“ Windows 10 Enterprise”之类的名称。
答案 2 :(得分:0)
除了Scott的答案之外,您还可以获得产品名称(例如Windows 10 Pro)(*我没有信任,因为Scott是提到注册表路径的人+我正在重用他的代码) :
using Microsoft.Win32;
string ProductName =
Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString();
Console.WriteLine(ProductName);
答案 3 :(得分:0)
private static ManagementObject GetMngObj(string className)
{
var wmi = new ManagementClass(className);
foreach (var o in wmi.GetInstances())
{
var mo = (ManagementObject)o;
if (mo != null) return mo;
}
return null;
}
public static string GetOsVer()
{
try
{
ManagementObject mo = GetMngObj("Win32_OperatingSystem");
if (null == mo)
return string.Empty;
return mo["Version"] as string;
}
catch (Exception e)
{
return string.Empty;
}
}
如何使用:
Console.WriteLine(GetOsVer());
结果:10.0.0.1299