Thursday, August 11, 2011

Disable XP security warning (to avoid hanging SCCM advertisement)

When running a install program, some times the XP security warning blocks the advertisement from running. The dialog box should only popup for applications starting from an "untrusted" source, and including the path as trusted in IE should disable that check.

For some reason, this does not seem to make any difference at all times. The popup blocks the program and the advertisement will eventually time out and fail.

To avoid this the security check can be disabled before running the program and re-enabled when its done by calling the setup from a vbscript. In the script below the exit code from the program is parsed to translate the exit code from the vendors "reboot needed" to 3210 which is the code SCCM uses to wait for reboot.



Option Explicit
Dim oFSO,oWsh,oEnv
Set oWsh=CreateObject("Wscript.Shell")
Set oFSO=CreateObject("Scripting.FileSystemObject")
Set oEnv = oWsh.Environment("Process")

Dim sProgram
sProgram = GetPath(Wscript.ScriptFullName) & "\Setup.exe"

If oFSO.FileExists(sProgram) Then
'Disable the security warning when starting the program
oEnv("SEE_MASK_NOZONECHECKS") = 1
Dim sCmd
sCmd = """" & sProgram & """ -s -overwrite"
wscript.echo sCmd
Dim iRet
On Error Resume Next
iRet = oWsh.Run(sCmd, 0, True)
'Enable security warnings
oEnv.Remove("SEE_MASK_NOZONECHECKS")

If Err Then
Wscript.Quit iRet
End If
If iRet = 14 Then
Wscript.Quit 3010
End If
Wscript.Quit iRet
Else
Wscript.Quit 1
End If

'*********************************************************
' Purpose: Return Path for filename
' Inputs: FullFileName
' Returns: PathName
'*********************************************************
Function GetPath(FileName)
Dim iPos

iPos=InStrRev(FileName,"\")
If iPos>0 Then
GetPath=Mid(FileName,1,iPos-1)
Else
GetPath=FileName
End If
End Function