Tag Archives: C# VB SCript

Detect Windows Version with VB Script

This post as most of my other posts is dedicated to windows developers :)Many times you are in the scenario where you want to detect the Operating System Version on the client machine. I had this when i developed a windows application and wanted to deploy it on different platforms including Windows 2000 XP or whatever NT hahaha this works for all .

So i wanna share just in case anyone has the same scenario :
I have shown the message boxes for debug purposes . Feel free to use or modify it : D happy development

‘ Muhammad Asad Siddiqi
‘ This can be run by executing cscript and passing the file name in the command prompt
‘ Purpose = “To detect the current version of the windows and execute files for XP or NT
‘ This would be made a part of Fail Safe to decide on PULIST or TaskList commands
‘ Variables used in the script
DIM   szTempFileName
DIM   szCommand     
DIM   wShell , FileObject    
DIM   nErrorCode
DIM   remoteAppFile
DIM   szLine 
DIM   ResultNT,ResultXP1,ResultXP2

‘ Create the temporary file as C:\TEMP\WindowsVersion_CT.txt

‘ Initialize the Windows Scripting Shell instance
Set WShell = CreateObject(“Wscript.Shell”)

‘ Initialize the Windows Scripting File instance
Set FileObject = Wscript.CreateObject(“Scripting.FileSystemObject”)

‘ DEBUG # 1 TODO – Remove This
MsgBox (“Starting”)

‘ Check if the file already exists delete it
if FileObject.FileExists(szTempFileName) then
End if

‘ DEBUG # 1 TODO – Remove This
MsgBox (“File System Checked”)
MsgBox (szTempFileName)

‘ Execute the ver command to get the windows info detail
szCommand = “%comspec% /c ver >”& szTempFileName

‘ DEBUG # 1 TODO – Remove This
MsgBox (szCommand)

‘ Execute the command and get the error code
nErrorCode = wShell.Run (szCommand , 0, TRUE)
‘ Check if the command is ran successfully
if nErrorCode = 0 then

‘Get a handle to the file where result of ver command is written
Set remoteAppFile = FileObject.OpenTextFile( szTempFileName , 1 , TRUE )

      ‘ Loop through the file till end of file character is not encountered
      do while not remoteAppFile.AtEndOfStream

              ‘ Read the line from the file
       szLine = remoteAppFile.ReadLine 
              ‘ If the line we have read is not an empty line then check 
              if szLine <> “” then    

        ResultNT = InStr(szLine, “4.0”)
        ResultXP1 = InStr(szLine, “XP”)
                     ResultXP2 = InStr(szLine, “5.1”)  
                      if ( ResultNT <> 0) then
               elseif (ResultXP1 <> 0) then
                      elseif (ResultXp2 <> 0) then
          MsgBox(“Unknown Windows”)             
               end if
              End If

 if FileObject.FileExists(szTempFileName) then
 End if

End if


Filed under 1