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

Capture Cancel button

3 views
Skip to first unread message

Sal

unread,
Oct 3, 2003, 12:40:53 PM10/3/03
to
Does anyone know how to capture the cancel button in VB for SP4
installation? Basically what I am trying to do is install SP4 using a Logon
Script but if a users click on the Cancel button I want to display a MsgBox
stating "You are not suppose to press cancel" , but if the user lets it run
and complete the install display the "SP4 has been installed"

Thanks
Sal


Torgeir Bakken (MVP)

unread,
Oct 6, 2003, 6:14:47 AM10/6/03
to
Sal wrote:

Hi


Do
iReturnCode = InstallSP
If iReturnCode = 0 Or iReturnCode = 3010 Then
MsgBox _
"SP4 has been installed", vbInformation, "Service Pack Installation"
ElseIf InstallSP = 1603 Then
MsgBox _
"You are not supposed to press cancel, installation will run again", _
vbExclamation, "Service Pack Installation"
Else
MsgBox _
"SP4 installation failed", _
vbCritical, "Service Pack Installation"

End If
Loop Until iReturnCode <> 1603


Function InstallSP
sCmd = "L:\Win2k\English\SP4\I386\UPDATE\UPDATE.EXE -U -Z"
Set oShell = CreateObject("WScript.Shell")
InstallSP = -1 ' init value
InstallSP = oShell.Run(sCmd, 1, True)
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


Sal

unread,
Oct 6, 2003, 12:01:49 PM10/6/03
to
Thanks but it still doesn't seem to work. I have posted the script below.
Maybe you can help by telling me what is wrong.

Dim oShell


Set oShell = CreateObject("WScript.Shell")

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

If sOStype = "WinNT" Then
If GetOsVersionNumber() = 5 Then
' OS is Win2k
' Get Service Pack level
If GetSPNumber() < 4 Then
' SP3 needs to be installed

' adjust path here
oShell.Run
"\\Server\OS\WIN2000\win2ksp4\I386\Update\Update.Exe -U -N -Z", 1, True


Do
iReturnCode = InstallSP
If iReturnCode = 0 Or iReturnCode = 3010 Then
MsgBox _
"SP4 has been installed", vbInformation, "Service Pack Installation"
ElseIf InstallSP = 1603 Then
MsgBox _
"You are not supposed to press cancel, installation will run again", _
vbExclamation, "Service Pack Installation"
Else
MsgBox _
"SP4 installation failed", _
vbCritical, "Service Pack Installation"

End If
Loop Until iReturnCode <> 1603

' use "." for local computer
ShutDown ".", "Reboot"
End If
End If

If GetOsVersionNumber() = 5.1 Then
' OS is WinXP
' Get Service Pack level
If GetSPNumber() < 1 Then
' SP1 needs to be installed

' adjust path here
oShell.Run "\\Server\OS\XP_PRO\WinXPsp1a\Update\Update.Exe -U -N -Z", 1,
True
If iReturn = "0" Then
' It can take some time before the reboot happen
' Halt the script for 30 seconds!
WScript.Sleep 30000
Elseif iReturn = "1603" Then
MsgBox "ERROR installing the Service Pack. You are not
supposed to press Cancel ;-). Please contact IT"
Else
MsgBox "SP1 is installed, press OK to reboot", _
vbInformation, "Service Pack Install"
End If

' 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

sRegPath = "HKLM\SOFTWARE\Microsoft\Internet Explorer\Version"

Set oShell = CreateObject("Wscript.Shell")
On Error Resume Next
sIEVer = oShell.RegRead(sRegPath)

If Err <> 0 Or sIEVer < "6.0.2800.1106" Then
' IE6 6.0.2800.1106 needs to be installed

' adjust path here
oShell.Run "\\Server\InternetExplorer\IE6SP1\ie6setup.exe", 1, True

MsgBox "IE6SP1 is installed, press OK to reboot", _
vbInformation, "Internet Explorer 6SP1 Install"

' use "." for local computer
ShutDown ".", "Reboot"
End If

If Err <> 0 Or sIEVer = "" Then
' IE version is 3.0 or less, set it to 0
sIEVer = "0.0.0.0"
End If
On Error Goto 0
aIEVer = Split(sIEVer, ".")
iMajorVersion = Cint(aIEVer(0))
iMinorVersion = Cint(aIEVer(1))
iBuildVersion = Cint(aIEVer(2))
iSubBuildVersion = Cint(aIEVer(3))
End If

Sal


"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3F814096...@hydro.com...

Torgeir Bakken (MVP)

unread,
Oct 6, 2003, 8:28:54 PM10/6/03
to
Sal wrote:

> Thanks but it still doesn't seem to work. I have posted the script below.
> Maybe you can help by telling me what is wrong.
>
> Dim oShell
> Set oShell = CreateObject("WScript.Shell")
> sOStype = oShell.RegRead(_
> "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions\ProductType")
>
> If sOStype = "WinNT" Then
> If GetOsVersionNumber() = 5 Then
> ' OS is Win2k
> ' Get Service Pack level
> If GetSPNumber() < 4 Then
> ' SP3 needs to be installed
>
> ' adjust path here
> oShell.Run
> "\\Server\OS\WIN2000\win2ksp4\I386\Update\Update.Exe -U -N -Z", 1, True
> Do
> iReturnCode = InstallSP

You do not pick up the return code from the Run method as well as not putting it
inside the Do loop, and your script has not included my function InstallSP (that
picks up the return code from Run method and returns it in the function value).

I have corrected (and cleaned up a bit as well) your script , replace all your
your code above the "Function GetOsVersionNumber()" with the following:


Dim oShell
Set oShell = CreateObject("WScript.Shell")
sOStype = oShell.RegRead(_
"HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions\ProductType")

SetLocale "en-us" ' do not remove

If sOStype = "WinNT" Then

If GetOsVersionNumber() = 5 And GetSPNumber() < 4 Then
' OS is Win2k and Service Pack level is less than 4
' SP4 needs to be installed

Do
' adjust path here
iReturnCode = oShell.Run _
("\\Server\OS\WIN2000\win2ksp4\I386\Update\Update.Exe -U -N -Z", _
1, True)

If iReturnCode = 0 Or iReturnCode = 3010 Then

MsgBox "Windows 2000 SP4 is installed, press OK to reboot", _
vbInformation, "Service Pack Install"


' use "." for local computer
ShutDown ".", "Reboot"

ElseIf iReturnCode = 1603 Then


MsgBox _
"You are not supposed to press cancel, installation will run again", _
vbExclamation, "Service Pack Installation"
Else
MsgBox _

"Windows 2000 SP4 installation failed", _


vbCritical, "Service Pack Installation"
End If
Loop Until iReturnCode <> 1603

ElseIf GetOsVersionNumber() = 5.1 And GetSPNumber() < 1 Then
' OS is WinXP and Service Pack level is less than 1


' SP1 needs to be installed

Do
' adjust path here
iReturnCode = oShell.Run _
("\\Server\OS\XP_PRO\WinXPsp1a\Update\Update.Exe -U -N -Z", 1, True)

If iReturnCode = 0 Or iReturnCode = 3010 Then

MsgBox "Windows XP SP1 is installed, press OK to reboot", _
vbInformation, "Service Pack Install"


' use "." for local computer
ShutDown ".", "Reboot"

ElseIf iReturnCode = 1603 Then


MsgBox _
"You are not supposed to press cancel, installation will run again", _
vbExclamation, "Service Pack Installation"
Else
MsgBox _

"Windows XP SP1 installation failed", _


vbCritical, "Service Pack Installation"
End If
Loop Until iReturnCode <> 1603

End If
End If

Sal

unread,
Oct 9, 2003, 5:39:06 PM10/9/03
to
THANKS AGAIN Torgeir That WORKED perfectly!


"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message

news:3F8208C6...@hydro.com...

0 new messages