Click here to Skip to main content
15,886,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to target Windows 7 from VB.Net code and using the following code I am able to return a string containing the version of Windows on the machine.
My.Computer.Info.OSFullName

For instance this returns "Microsoft Windows 7 Enterprise" on my development machine.

My question is, would I be safe to search the returned string for "Windows 7" across several languages or are there different translations of this?

Most notably I've had trouble with French, German and Swedish in the past when checking system strings for other projects.
Posted

VB
VB
Public Shared Function Win7CurrentOS() As Boolean
     If Environment.OSVersion.Version.Major = 6 And Environment.OSVersion.Version.Minor = 1 Then
         Return True
     Else
         Return False
     End If
 End Function


C#
C#
static bool Win7CurrentOS()
     {
         if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
 
Share this answer
 
v2
Comments
Bob - Pakman 22-Sep-10 11:01am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
You never use strings to compare or retrieve such information because of possible cultural difference in the strings. You always use numeric data whenever possible, such as, in your case, the Windows version number.
 
Share this answer
 
Comments
Bob - Pakman 23-Sep-10 3:13am    
Thanks for that Dave. I am highly aware of cultural differences between operating systems, especially when it comes to date formats! In this instance, one consideration was that "Windows" is a product name, and therefore unlikely to change between languages, but you're absolutely right, safer using the number!

Thanks again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900