WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

64-bit

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How To Check If Computer Is Running A 32 Bit or 64 Bit Operating System

 Keywords: OS Platform Version Bit Bitness 32-bit 64-bit 

Question:

I am running a winbatch script against the registry on remote servers. Due to registry redirection, it won't work if I'm running on a 32-bit machine and the server is running a 64-bit O/S. So I want to check for that combination, display an error and get out.

I can't seem to find a function that will display the 'bitness' of either my location machine or the remote server.

Answer:

Local machine bitness can be determined using the WinMetrics Function.
If WinMetrics(-7)|WinMetrics(-2)==3 Then Pause('Windows Bitness','64-bit Platform')
Else Pause('Windows Bitness','32-bit Platform')

Remote machine can be determined using this Registry code:

intHandle = RegConnect("\\Otis", @REGMACHINE, "")
strPath = 'Hardware\Description\System\CentralProcessor\0'
strValue = RegQueryValue( intHandle, strPath:'[Identifier]')
result = StrIndex( strValue, 'x86', 1, @FWDSCAN)
If result
    Pause('Notice' , 'This is 32 Bit Operating system')
Else
    Pause('Notice' , 'This is 64 Bit Operating system')
EndIf
Or using this WMI Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; CheckRemoteOS Function ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#DefineFunction UDF_CheckRemoteOS(vstrTargetComputer)
   ; Set the program to goto the WBErrorHandler function if there is a problem.
   IntControl(73,3,0,"UDF_WBErrorHandler",0)

   ; Dimension an array.
   varrOSInfo = ArrDimension(1,5)

   ; connect to WMI
   Locator = ObjectCreate("WbemScripting.SWbemLocator")
   CIMService = Locator.ConnectServer(vstrTargetComputer, "root/cimv2")
   WMIService = Locator.ConnectServer(vstrTargetComputer, "root/wmi")
   WQL = "Select * From Win32_OperatingSystem"
   vcolOS = CIMService.ExecQuery(WQL)
   ForEach vobjItem In vcolOS
      varrOSInfo[0,0] = vobjItem.Caption
      varrOSInfo[0,1] = vobjItem.CSDVersion
      varrOSInfo[0,2] = vobjItem.BuildNumber
      varrOSInfo[0,3] = vobjItem.LastBootUpTime
      If StrIndexNC(vobjItem.Caption,"Windows",1,@FWDSCAN) != 0 && StrIndexNC(vobjItem.Caption,"XP",1,@FWDSCAN) != 0 Then
      ; It's Windows XP, find out if it's 64-bit
      If StrIndexNC(vobjItem.Caption,"x64 Edition",1,@FWDSCAN) != 0 Then
      ; It's 64-bit
      varrOSInfo[0,4] = "64-bit"
      Else
      varrOSInfo[0,4] = "32-bit"
      End If
      Else
      varrOSInfo[0,4] = vobjItem.OSArchitecture
      End If
   Next
   vobjItem = 0
   WMIService = 0
   CIMService = 0
   Locator = 0
   Return(varrOSInfo)

#EndFunction

vstrTargetComputer = "OTIS"
varrOSInfo = UDF_CheckRemoteOS(vstrTargetComputer)
Pause('Bitness',  varrOSInfo[0,4])
Exit

Article ID:   W17647
Filename:   How To Check If Computer Is Running A 32 Bit or 64 Bit Operating System.txt
File Created: 2014:02:10:10:43:26
Last Updated: 2014:02:10:10:43:26