VB.Net code for detecting OS (newbie here)

  • Thread starter Thread starter JH
  • Start date Start date
J

JH

I tried to run this code which I found on the web. But it always crashes. It
shows SysInfo1 is Null ...object refernce .....
I tried to add refernce ( Microsoft scripting runtime ,
Interop.SysInfoLib...), but every time it reaches this section the program
crashes.
Can somebody please ...help me !!!!!!!!! Newbie here

dimm SysInfo1 As SysInfoLib.SysInfo

With SysInfo1
Select Case .OSPlatform
Case 0: OS = "Win32"
Case 1:
Select Case .OSVersion
Case 4: OS = "Win 95"
Case 4.1: OS = "Win 98"
End Select
Case 2:
Select Case .OSVersion
Case 4: OS = "Win NT"
Case 5: OS = "Win 2000"
Case 6: OS = "Win XP"
End Select
End Select

End With
 
* "JH said:
I tried to run this code which I found on the web. But it always crashes. It
shows SysInfo1 is Null ...object refernce .....
I tried to add refernce ( Microsoft scripting runtime ,
Interop.SysInfoLib...), but every time it reaches this section the program
crashes.

Why not use 'Environment.OSVersion'?
 
JH,
dimm SysInfo1 As SysInfoLib.SysInfo
You defined a variable to hold a SysInfo object, but you never initialized
the variable with an actual object.

However I have to ask the same Question Herfried did. Have you looked at the
System.Environment class?

I don't remember what all SysInfo exposes, however I suspect all of it is
covered by other .NET classes. Making using SysInfoLib unnecessary!

Hope this helps
Jay
 
Back
Top