thanks in advance
Janet
Hi
Some questions:
Are the users local admins on the computers?
If not, do you have any tool that can elevate to a admin privilege in the logon
script?
--
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
> "Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
> news:3EB6EAA8...@hydro.com...
> > Janet wrote:
> >
> > > My manager wants me to check the current SP version on all our 2000
> > > workstations and if they are not at SP3 to install it.
> > > My manager wants this to be automated from the logon scripts.
> > > I do not know how to use WSH - I am only familiar with Basic scripts. I
> > > have a copy of osver.exe to check the version.
> > > Is there a sample on file somewhere that I could follow for this?
>
> Some questions:
> Are the users local admins on the computers? Yes they are local
> admins
Hi
First, a little side note, the WSH group is microsoft.public.scripting.wsh,
scriptlets is a group for WSC (Windows Script Components), and has very little
traffic ;-)
WSH 5.6 documentation (local help file) can be downloaded from here:
http://msdn.microsoft.com/downloads/list/webdev.asp
In the script below, I use "I386\Update\Update.Exe -U -N -Z" to install SP3. You
can use the W2Ksp3.exe file directly as well without expanding it.
Read this one if you haven't already
Service Pack 3 Installation and Deployment Guide
http://www.microsoft.com/windows2000/downloads/servicepacks/sp3/spdeploy.htm
for more on command line switches for a SP3 installation:
Command-Line Options for W2ksp3.exe and Update.exe
http://www.microsoft.com/windows2000/downloads/servicepacks/sp3/spdeploy.htm#command_line_switches_for_update_exe_and_w2ksp3_exe_nthj
Here you go:
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If GetOsVersionNumber() = 5 Then
' OS is Win2k
' Get Service Pack level
If GetSPNumber() < 3 Then
' SP3 needs to be installed
' adjust path here
oShell.Run "somepath\I386\Update\Update.Exe -U -N -Z", 1, True
MsgBox "SP3 is installed, press OK to reboot", _
vbInformation, "Service Pack Install"
' use "." for local computer
ShutDown ".", "Reboot"
End If
End If
Function GetOsVersionNumber()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Determines OS by reading reg val & comparing to known values
' OS version number returned as number of type double:
' Windows 95: 1
' Windows 98: 2
' Windows ME: 3
' Windows NT4: 4
' Windows 2k: 5
' Windows XP: 5.1
' Windows 2k3: 5.2
' Windows >2k3: >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 GetSPNumber()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Determines Service Pack number by reading reg val CSDVersion in
' HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion
'
' CSDVersion in System\CCS is updated AFTER a reboot when
' installing a SP
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim oShell, sOStype, sOSversion, iSPNumber, aSPNumber
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
GetSPNumber = "W9x"
Exit Function ' >>>
End If
iSPNumber = oShell.RegRead(_
"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion")
If Err.Number<>0 Then
GetSPNumber = 0
' Could not determine Service Pack
Exit Function ' >>>
End If
' CSDVersion is e.g. "Service Pack 2"
aSPNumber = Split(iSPNumber)
GetSPNumber = Cint(aSPNumber(2))
End Function
Sub ShutDown(sNode, sAction)
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" _
& sNode & "\root\cimv2")
Set colOperatingSystems = oWMI.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each obj in colOperatingSystems
Set oOS = obj : Exit For
Next
sAction = LCase(sAction)
Select Case sAction
Case "logoff"
iCmd = EWX_LOGOFF
Case "logoff_force"
iCmd = EWX_LOGOFF + EWX_FORCE
Case "shutdown"
iCmd = EWX_SHUTDOWN
Case "shutdown_force"
iCmd = EWX_SHUTDOWN + EWX_FORCE
Case "reboot"
iCmd = EWX_REBOOT
Case "reboot_force"
iCmd = EWX_REBOOT + EWX_FORCE
Case "poweroff"
iCmd = EWX_POWEROFF
Case "poweroff_force"
iCmd = EWX_POWEROFF + EWX_FORCE
Case Else
' Default value
iCmd = EWX_POWEROFF
End Select
oOS.Win32shutdown iCmd
End Sub
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3EB70B7E...@hydro.com...
> Thanks for the pointers and advice. I will read through the notes you have
> sent me.
> I do not know how to use WSH and was hoping for a script to run from the
> logon script.
> Do I need anything on the clients to run this script? Or can I use this
> script as it is?
Hi
You can use the script as it is, and you can use it from a logon script, and, no, you don't need anything on the clients to run it.
Put the code in a .vbs file, and launch it with
wscript.exe "path to vbs file"