Anyone Got A Function That Returns Which OS We're running on?

  • Thread starter Thread starter Siv
  • Start date Start date
S

Siv

Hi,
Does anyone have a function that when called returns which operating system
we are running on. E.g:

Select Case GetOSVer()
Case 1 'Win95
...
Case 2 'Win98
...
Case 3 'Win98SE
...
Case 4 'WinME
...
Case 5 'WinNT4
...
Case 6 'Win2k
...
Case 7 'WinXP
...
End select

I'm sure I could figure out my own version, but why re-invent the wheel!

Siv
 
Hi, try this....

Dim os As String
os = System.Environment.OSVersion.ToString
MsgBox(os)

there are a few diff options under OSVersion including platform etc, so you get look at the enum for the diff os's and use then platform number in your select.

Cheers
Adam
 
Try this;

Public Function GetOSVersion() As String
Select Case Environment.OSVersion.Platform
Case PlatformID.Win32S
Return "Win 3.1"
Case PlatformID.Win32Windows
Select Case Environment.OSVersion.Version.Minor
Case 0
Return "Win95"
Case 10
Return "Win98"
Case 90
Return "WinME"
Case Else
Return "Unknown"
End Select
Case PlatformID.Win32NT
Select Case Environment.OSVersion.Version.Major
Case 3
Return "NT 3.51"
Case 4
Return "NT 4.0"
Case 5
Select Case _
Environment.OSVersion.Version.Minor
Case 0
Return "Win2000"
Case 1
Return "WinXP"
Case 2
Return "Win2003"
End Select
Case Else
Return "Unknown"
End Select
Case PlatformID.WinCE
Return "Win CE"
End Select
End Function
 
Thanks for that,
I will give it a try.
Siv
Hi, try this....

Dim os As String
os = System.Environment.OSVersion.ToString
MsgBox(os)

there are a few diff options under OSVersion including platform etc, so you get look at the enum for the diff os's and use then platform number in your select.

Cheers
Adam
 
It did work brilliantly, thanks Gerry.

For completeness, people have asked in the past if it's possible to
distinguish between different "flavors" of XP, like Home, Pro, Tablet, and
Media Center. I haven't seen a satisfactory solution to that one yet.
 
Jeff,
According to the Microsoft Tablet PC SDK:

<quote>
Q. How can I determine if my application is running on a Tablet PC?
A. Use the Windows GetSystemMetrics API and pass in SM_TABLETPC as the value
of the index. SM_TABLETPC is defined in Winuser.h. The value of SM_TABLETPC
is 86. The method returns True or nonzero if the Microsoft Windows XP Tablet
PC Edition operating system is running; False or zero otherwise.

Applications should not rely on a true or nonzero value to mean all Tablet
PC components are installed and working. See the following question for
details on how to determine if Tablet PC components are installed.

</quote>

There is also a MediaCenter system metrics value.

I would expect System.Windows.Forms.SystemInformation would list both values
as it gives most other SystemMetrics, however it appears to be missing
TabletPC (SM_TABLETPC) & MediaCenter (SM_MEDIACENTER).

You can use code similar to:

Public Enum SystemMetric As Integer
TabletPC = 86
MediaCenter = 87
End Enum

Declare Auto Function GetSystemMetrics Lib "User32" (ByVal index As
SystemMetric) As Integer

If GetSystemMetrics(SystemMetric.TabletPC) <> 0 Then
Debug.WriteLine("On a Tablet PC")
Else
Debug.WriteLine("Not on a Tablet PC")
End If

If GetSystemMetrics(SystemMetric.MediaCenter ) <> 0 Then
Debug.WriteLine("On a Media Center PC")
Else
Debug.WriteLine("Not on a Media Center PC")
End If

I've used the Tablet PC value reliably, I don't have a Media Center PC to
verify the Media Center value.

I'm not sure how to tell the difference between Home & Pro.

Hope this helps
Jay
 
I've used the Tablet PC value reliably, I don't have a Media Center PC to
verify the Media Center value.

I may check it at home if I get the urge. Media Center rocks, by the way.
I'm not sure how to tell the difference between Home & Pro.

Now if only I can find the thread I saw where no one had a good answer to
this question I can give them yours.... (I think it was a different group.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top