Detect Operating System
I would like to know how to detect if a persons operating system is Windows 7, I'm a bit new and have no idea how to do this. Please let me know if it is possible and the code to 开发者_运维问答do it.
See the Environment.OSVersion
property on MSDN. It is a static property that returns an OperatingSystem
object, which has a Version
property and you can just check the Major
and Minor
version numbers to see if it is 6.1 (Windows 7 is actually version 6.1).
Dim osVer As Version = Environment.OSVersion.Version
If osVer.Major = 6 And osVer.Minor = 1 Then
Console.WriteLine("win7!!")
End If
It's easy to use My.Computer.Info.OSFullName
.
you need to set up the app.manifest
file to get the correct version number. even System.Environment.OSVersion.ToString() '
not gives the correct version if you have not been set the app.manifest
add an app.manifest
Console.WriteLine(My.Computer.Info.OSFullName)
Console.WriteLine(My.Computer.Info.OSVersion)
Console.WriteLine(My.Computer.Info.OSPlatform)
Output:
Microsoft Windows 10 Pro
10.0.18362.0
Win32NT
I'm guessing since you're a bit new that you're actually using VB.NET rather than classic VB 6.
In VB.NET, you can use:
Dim osVersion As String = System.Environment.OSVersion.ToString()
I would use
My.Computer.Info.OSFullName
精彩评论