Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

detect OS

5 views
Skip to first unread message

CodeAnimal.com

unread,
Jun 21, 2002, 9:21:51 AM6/21/02
to
Can someone help me write a script to detect the OS of a machine? The
script will be running on a server and remote work stations (with any MS OS)
will be connecting to it. I need something similar to below:

If Windows 2000 Then

'run this script......

If Windows XP Then

'run this scripts


etc......


Jeff Wright

unread,
Jun 21, 2002, 9:45:27 AM6/21/02
to
I am new to scripting but I have addressed this with help of a GETOS
Functions provided to me by Torgeri recently.

Hope this helps.

Jeff Wright


if GetOS = ("WXP") then
' DO SOMETHING
Else
if GetOS = ("W2k") then
' DO SOMETHING FOR 2000
Else
' Tell the user the script is designed to run on Windows XP or
' Windows 2000 and exit
End if
End if

'##################################################################
Function GetOS()
' From Torgeir Bakken
' using the ver command

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\runresult.tmp"

oShell.Run "%comspec% /c ver >" & sTempFile, 0, True

Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsASCII)

sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)

Select Case True
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
'################################################################

Jeff Wright

unread,
Jun 21, 2002, 9:46:20 AM6/21/02
to
Oops..that should have been "Torgeir" : )

J

On Fri, 21 Jun 2002 13:45:27 GMT, Jeff Wright <jsw...@yahoo.com>
wrote:

Chris Shelley [MS]

unread,
Jun 21, 2002, 10:30:41 AM6/21/02
to
You can always query the registry at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion for example
you should get "Microsoft Windows XP".
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"CodeAnimal.com" <in...@codeanimal.com> wrote in message
news:OTyp$ZSGCHA.2616@tkmsftngp10...

CodeAnimal.com

unread,
Jun 21, 2002, 10:39:35 AM6/21/02
to
perfect, thanks....

"Jeff Wright" <jsw...@yahoo.com> wrote in message
news:j6b6huo5676vceg0a...@4ax.com...

alex_k._angelopoulos_(mvp)

unread,
Jun 21, 2002, 10:42:23 AM6/21/02
to
Won't work with the Win9x/Me clients, though. ( I know, I'd like to forget
about them too).

"Chris Shelley [MS]" <cshe...@online.microsoft.com> wrote in message
news:OzQldATGCHA.2680@tkmsftngp12...

Bill Stewart

unread,
Jun 25, 2002, 1:10:07 PM6/25/02
to
"CodeAnimal.com" <in...@codeanimal.com> wrote in message
news:OTyp$ZSGCHA.2616@tkmsftngp10...

> Can someone help me write a script to detect the OS of a machine? The script


> will be running on a server and remote work stations (with any MS OS) will be
> connecting to it.

Try my osver.exe.

http://mywebpages.comcast.net/stewartb/files/admtool2.zip

Usage: OSVER [-s] [-t] [-q]

Without -s or -t, returns OS version as an exit code value:
0 = Unknown OS
1 = Windows 95
2 = Windows 98
3 = Windows Me
4 = Windows NT 4.0
5 = Windows 2000
6 = Windows XP

With -s, returns the NT (or later) service pack number as an
exit code value. -s on a non-NT system returns an exit code of 99.

With -t, returns NT type:
0 = Not running NT/failed to determine NT type
1 = Workstation
2 = Server (not domain controller)
3 = Server (domain controller)

-q specifies quiet mode (no output).


0 new messages