Could someone please help me(a non AppDev person) put a
script together that will determine OS type and then
execute a file germane to the result, that I could either
place in a login script or execute manually?

I.e.
WINNT = NT4.exe
WIN2KSRV = NT2KSRV.EXE

Thank you in advance,

Bart

Re: OS SCRIPT by Torgeir

Torgeir
Tue Sep 16 18:00:37 CDT 2003

BartJ wrote:

> Could someone please help me(a non AppDev person) put a
> script together that will determine OS type and then
> execute a file germane to the result, that I could either
> place in a login script or execute manually?
>
> I.e.
> WINNT = NT4.exe
> WIN2KSRV = NT2KSRV.EXE

Hi

See below for an shot at this. If you need to differentiate on workstation and
server as well, I have also added the function GetPlatform() below (but I don't
make any callout to it in the main script).

WSH 5.6 documentation (local help file) can be downloaded from here if you
haven't got it already:
http://msdn.microsoft.com/downloads/list/webdev.asp



Set oShell = CreateObject("Wscript.Shell")

sOSVer = GetOsVersionNumber

If sOSVer = 4 Then
' NT 4
oShell.Run "NT4.exe", 1, True

ElseIf sOSVer = 5 Then
' Win2k
oShell.Run "NT2KSRV.EXE", 1, True
End If




Function GetOsVersionNumber()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Determines OS by reading reg val & comparing to known values
' OS version number returned as number of type double:
' Windows 2k: 5
' Windows XP: 5.1
' Windows Server 2003: 5.2
' Windows x: >5.2

' Note: Decimal point returned is based on the Locale setting
' of the computer, so it might be returned as 5,1 as well.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim oShell, sOStype, sOSversion
Set oShell = CreateObject("Wscript.Shell")

On Error Resume Next
sOStype = oShell.RegRead(_
"HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions\ProductType")
If Err.Number<>0 Then
' Hex(Err.Number)="80070002"
' - Could not find this key, OS must be Win9x
Err.Clear

sOStype = oShell.RegRead(_
"HKLM\SOFTWARE\Microsoft\Windows" & _
"\CurrentVersion\VersionNumber")

Select Case sOStype
Case "4.00.950"
sOSversion = 1 ' Windows 95A
Case "4.00.1111"
Dim sSubVersion
sSubVersion = oShell.RegRead(_
"HKLM\SOFTWARE\Microsoft\Windows" & _
"\CurrentVersion\SubVersionNumber")
Select Case sSubVersion
Case " B"
sOSversion = 1 ' Windows 95B
Case " C"
sOSversion = 1 ' Windows 95C
Case Else
sOSversion = 1 ' Unknown Windows 95
End Select
Case "4.03.1214"
sOSversion = 1 ' Windows 95B
Case "4.10.1998"
sOSversion = 2 ' Windows 98
Case "4.10.2222"
sOSversion = 2 ' Windows 98SE
Case "4.90.3000"
sOSversion = 3 ' Windows Me
Case Else
sOSversion = 1 ' Unknown W9x/Me
End Select
Else ' OS is NT based
sOSversion = oShell.RegRead(_
"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
If Err.Number<>0 Then
GetOsVersion = "Unknown NTx"
' Could not determine NT version
Exit Function ' >>>
End If
End If

' Setting Locale to "en-us" to be indifferent to country settings.
' CDbl might err else
SetLocale "en-us"
GetOsVersionNumber = CDbl(sOSversion)
End Function



Function GetPlatform()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Determines platform by reading reg val & comparing to known values
' Platform type returned as:
' "client", "server", "wts"
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim oShell, sOStype, sOSversion
Set oShell = CreateObject("Wscript.Shell")

On Error Resume Next
sOStype = oShell.RegRead(_
"HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions\ProductType")
If Err.Number<>0 Then
' Hex(Err.Number)="80070002"
' - Could not find this key, OS must be Win9x
Err.Clear
GetPlatform = "client"
Exit Function ' >>>
End If


sOStype = oShell.RegRead(_
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control" & _
"\ProductOptions\ProductType")

If Err.Number<>0 Then
GetPlatform = "client"
' Could not determine NT version
Exit Function ' >>>
End If

Select Case sOStype
Case "4.0"
sOStype = "wts"
Case "LanmanNT"
sOStype = "server"
Case "ServerNT"
sOStype = "server"
Case "WinNT"
sOStype = "client"
Case Else
sOStype = "client"
End Select
GetPlatform = sOStype
End Function



--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter