Login | |
|
 |
Using WshShell.Run - 8/29/2005 11:27:28 PM
|
|
 |
|
| |
mbouchard
Posts: 1804
Score: 12
Joined: 5/15/2003
From: USA
Status: online
|
msgbox GetOS Function GetOS() 'Will work with most versions of WSH. 'CMD window will not display. Const OpenAsASCII = 0 Const FailIfNotExist = 0 Const ForReading = 1 Dim WshShell : Set WshShell = CreateObject("WScript.Shell") Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject") Dim sTemp, sTempFile, fFile, sResults sTemp = WshShell.ExpandEnvironmentStrings("%TEMP%") sTempFile = sTemp & "\runresult.tmp" WshShell.Run "%comspec% /c ver >" & sTempFile, 0, True Set fFile = FSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII) sResults = fFile.ReadAll fFile.Close FSO.DeleteFile(sTempFile) Select Case True 'Add more info to the 98 and 95 to get the specific version. i.e. 98SE 95 a,b,or c Case InStr(sResults, "Windows 95") > 1 : GetOS = "W95" Case InStr(sResults, "Windows 98") > 1 : GetOS = "W98" Case InStr(sResults, "Windows Millennium") > 1 : GetOS = "WME" Case InStr(sResults, "Windows NT") > 1 : GetOS = "NT4" Case InStr(sResults, "Windows 2000") > 1 : GetOS = "W2K" Case InStr(sResults, "Windows XP") > 1 : GetOS = "WXP" Case Else : GetOS = "Unknown" End Select End Function
< Message edited by mbouchard -- 9/15/2005 11:17:18 PM >
_____________________________
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|
| |
|
|
|
 |
Using WshShell.Exec - 8/29/2005 11:28:18 PM
|
|
 |
|
| |
mbouchard
Posts: 1804
Score: 12
Joined: 5/15/2003
From: USA
Status: online
|
msgbox GetOS Function GetOS() 'Requires WSH 5.6 'CMD window will flash as there is no way to supress it when using exec. Dim WshShell : Set WshShell = CreateObject("WScript.Shell") Dim strVer : set strVer = WshShell.exec("%comspec% /c ver") Dim sResults sResults = strVer.stdout.readall Select Case True 'Add more info to the 98 and 95 to get the specific version. i.e. 98SE 95 a,b,or c Case InStr(sResults, "Windows 95") > 1 : GetOS = "W95" Case InStr(sResults, "Windows 98") > 1 : GetOS = "W98" Case InStr(sResults, "Windows Millennium") > 1 : GetOS = "WME" Case InStr(sResults, "Windows NT") > 1 : GetOS = "NT4" Case InStr(sResults, "Windows 2000") > 1 : GetOS = "W2K" Case InStr(sResults, "Windows XP") > 1 : GetOS = "WXP" Case Else : GetOS = "Unknown" End Select End Function
_____________________________
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|
| |
|
|
|
 |
RE: Using WshShell.Exec - 8/29/2005 11:28:59 PM
|
|
 |
|
| |
mbouchard
Posts: 1804
Score: 12
Joined: 5/15/2003
From: USA
Status: online
|
msgbox GetOS Function GetOS() 'WMI is required for this script to function Dim strComputer, strWMIOS 'If you only want to use locally, remove the inputbox and make strComputer = "." strComputer = Inputbox("Input the name of the remote computer or hit enter for this PC.") If strComputer = "" then strComputer = "." End if Dim objWmiService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\cimv2") Dim strOsQuery : strOsQuery = "Select * from Win32_OperatingSystem" Dim colOperatingSystems : Set colOperatingSystems = objWMIService.ExecQuery(strOsQuery) Dim objOs Dim strOsVer For Each objOs in colOperatingSystems strWmios = objOs.Caption & " " & objOs.Version Next Select Case True 'Add more info to the 98 and 95 to get the specific version. i.e. 98SE 95 a,b,or c Case InStr(strWmiOS, "2000 Server") > 1 : GetOS = "2KSRV" Case InStr(strWmiOS, "2003, Standard") > 1 : GetOS = "2K3SRV" Case InStr(strWmiOS, "2003, Enterprise") > 1 : GetOS = "2K3ENTSRV" Case InStr(strWmiOS, "2000 Advanced Server") > 1 : GetOS = "2KADVSRV" Case InStr(strWmiOS, "Windows NT") > 1 : GetOS = "NT4" Case InStr(strWmiOS, "Windows 2000") > 1 : GetOS = "W2K" Case InStr(strWmiOS, "Windows XP") > 1 : GetOS = "WXP" Case Else : GetOS = "Unknown" End Select End Function
_____________________________
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|