Quantcast
Channel: Scripting Languages
Viewing all articles
Browse latest Browse all 42

How to get OS and Shell Architecture as well as Version of VBScript

$
0
0

Hello community,

 

to work with x64 systems is now a normal scenario in the business. x86 (32 bit) and x64 (64 bit) programs works simultaneously peaceful hand in hand. But for the scripts it is sometimes a big difference to work on an x86 or x64 system, and whether it is an x86 or x64 process. Here a VBScript with two functions to differentiate between all those constellations.

 

'-Begin-----------------------------------------------------------------

 

  '-Directives----------------------------------------------------------

    Option Explicit

 

  '-Constants-----------------------------------------------------------

    Const WMIPath = "winmgmts:root\cimv2:Win32_Processor='cpu0'"

 

  '-WhichOS-------------------------------------------------------------

    Function WhichOS()

      If GetObject(WMIPath).AddressWidth = 32 Then

        WhichOS = "x86"

      ElseIf GetObject(WMIPath).AddressWidth = 64 Then

        WhichOS = "x64"

      End If

    End Function

 

  '-WhichShell----------------------------------------------------------

    Function WhichShell()

 

      '-Variables-------------------------------------------------------

        Dim WshShell, WshProcEnv, ProcArch

 

      Set WshShell =  CreateObject("WScript.Shell")

      Set WshProcEnv = WshShell.Environment("Process")

      ProcArch = WshProcEnv("PROCESSOR_ARCHITECTURE")

      If ProcArch = "AMD64" Or ProcArch = "IA64" Or _

        ProcArch = "EM64T" Then

        WhichShell = "x64"

      Else

        WhichShell = "x86"

      End If

      Set WshProcEnv = Nothing

      Set WshShell = Nothing

 

    End Function

 

  '-Main----------------------------------------------------------------

    MsgBox "VBScript " & WScript.Version & " on " &  WhichShell() & _

      " Shell on " & WhichOS() & " OS"

 

'-End-------------------------------------------------------------------

 

The function WhichOS differentiate between the OS architecture via Windows Management Instrumentarium (WMI) and the function WhichShell differentiate between the process architecture via the system variable PROCESSOR_ARCHITECTURE. On this way you can safely detect the existing constellation.

 

Here an example of the script in different command shells on an x64 Windows.

001.JPG

 

Enjoy it.

 

Cheers

Stefan


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>