Retrieve computer operating system name

Share this post
FaceBook  Twitter  Mixx.mn     

To retrieve computer operating system name, use following code:
Steps:
1) Get an object from winmgmts root\CIMV2

2) Execute SQL to retrieve operating system information

3) Display the OS name

Code:

Dim    objWMIService,   colItems  ,OSname
strComputer="."

'1) Get an object from winmgmts root\CIMV2'
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

'2) Execute SQL to retrieve operating system information'
Set colItems = objWMIService.ExecQuery( _
         "SELECT * FROM Win32_OperatingSystem",,48)

3) Display the OS name
   For Each objItem in colItems
       OSname = objItem.Caption
   Next

  if Instr(OSname,"Windows 7")>0 then   
     if (instr(strValue,"x86")) then
         Msgbox ("Windows 7-32 bit")
     Elseif (instr(strValue,"64")) then
           Msgbox ("Windows 7-64 bit")
     end if
    Else
           Msgbox OSname
  End if 

msgbox OSname