Hello,

I have two scripts that run correctly by themselves but when I call the second
from within the first the process does not occur. I cannot read the error - the
cmd box goes away too quickly.

The first script will be called from the user logon script. The second will be
run with elevated privileges and is called by the first. As I said above, each
run correctly alone but fail when run together.

When these scripts are run together, the process gets to the first message box
in the second script then fails. I have marked with a row of "+" signs where
the second script fails. I have run this script as a domain admin, local admin
and reqular user.

I have pasted the scripts below. All suggestions will be greatly appreciated.

TIA,
Bill Burke
bill@2burkes.com

'********************************
'********* First Script *********
'********************************
Option Explicit
On Error Resume Next
dim WshShell, WshEnv, WinPath, rc, oArgs, FSO, sUser, sCmd, sPass

sUser="susAdmin"
sCmd="cscript /nologo c:\susRegChg.vbs"
sPass="**************" & vbCrLf

set WshShell = CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
WinPath = WshEnv("SystemRoot")&"\System32\runas.exe"

' Check to make sure the system is not a W2K or NT server.
set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists("C:\WINNT\SYSTEM32\LDIFDE.EXE") Then
WScript.Quit
Elseif FSO.FileExists("C:\WINDOWS\SYSTEM32\LDIFDE.EXE") Then
WScript.Quit
Elseif FSO.FileExists("C:\WINNT\SYSTEM32\PBRUSH.EXE") Then
WScript.Quit
Elseif FSO.FileExists("C:\WINDOWS\SYSTEM32\PBRUSH.EXE") Then
WScript.Quit
End If

If FSO.FileExists(winpath) Then
'wscript.echo winpath & " " & "verified"
Else
wscript.echo "!! ERROR !!" & VBCRLF & "Can't find or verify " & _
winpath &"." & VBCRLF & "You must be running Windows 2000 for _
this script to work."
set WshShell=Nothing
set WshEnv=Nothing
set oArgs=Nothing
set FSO=Nothing
wscript.quit
End If

rc=WshShell.Run("runas /user:"& sUser & " " & CHR(34) & sCmd & CHR(34), 2, _
FALSE)
Wscript.Sleep 30
WshShell.AppActivate(WinPath)
WshShell.SendKeys sPass

set WshShell=Nothing
set oArgs=Nothing
set WshEnv=Nothing
set FSO=Nothing

wscript.quit


'********************************
'******** Second Script *********
'********************************
Option Explicit
Dim strComputer, stdOut, oReg, strKeyPath, strKeyPath2
Dim objShell, strValueName, strValue, strYear, strMonth, strDay
Dim strHour, strMinute, strCurrentDate, strCurrentTime, oShell
Dim sEnvVarValue1, strLogonServer, objFSO, objTextFile, objEmail
Dim WshShell, BtnCode, strComputerName, strUserName

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Const ADS_PROPERTY_UPDATE = 2
Const ForAppending = 8
Const eventSUCCESS = 0

strYear = DatePart("yyyy", Now)
strMonth = DatePart ("m", Now)
strDay = DatePart ("d", Now)
strHour = DatePart ("h", Now)
strMinute = DatePart ("n", Now)
strCurrentDate = Right("0" & strMonth,2) & "-" & Right("0" & strDay,2) & "-" &
Right(strYear,2)
strCurrentTime = Right("0" & strHour,2) & ":" & Right("0" & strMinute,2)

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
strValueName = "WUServer"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If strValue = "http://172.16.146.18" Then
WScript.Quit
Else
' Create and destroy informational dialog box for end user information.
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup("AO's Windows Update Service is being _
installed on your system. " & vbCrLf & vbCrLf &_
"The installation process is completely automatic. " & _
vbCrLf & vbCrLf & "Please be patient, the process should take _
less that a minute. " & _
vbCrLf & vbCrLf & "(This message box will close itself in fifteen _
seconds...) ", 15, " Installing AO's Windows Update Service",0 + 64)
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

' Set variables to modify the local system's registry.
strKeyPath = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
strKeyPath2 = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath2

' Modify the local system's registry.

' Set objShell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUServer",
"http://172.16.146.18"
objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUStatusServer",
"http://172.16.146.18"

objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\NoAutoRebootWithLoggedOnUsers",
00000001, "REG_DWORD"
objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\RescheduleWaitTime",
00000015, "REG_DWORD"
objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\UseWUServer",
00000001, "REG_DWORD"
objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\NoAutoUpdate",
00000000, "REG_DWORD"
objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\AUOptions", 00000004,
"REG_DWORD"
objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\ScheduledInstallDay",
00000000, "REG_DWORD"
objShell.RegWrite
"HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\ScheduledInstallTime",
00000010, "REG_DWORD"

' Get the computer name and user name from the local "DOS" environment
strComputerName = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
strUserName = objShell.ExpandEnvironmentStrings("%USERNAME%")
WScript.Echo "Computer Name: " & strComputerName & vbCrlf & vbCrlf _
& "Username: " & strUserName

' Write to text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile
("\\USARNT03\SHARED\SUS_Update_Info\SUSupdateLog.txt", ForAppending, True)
objTextFile.WriteLine strComputerName & "," & strUserName & "," & strCurrentDate
& "," & strCurrentTime & "," & "Successful SUS Update"

' Below email section will not work in AO's environment
' Send an email notifying successful update
' Set objEmail = CreateObject("CDO.Message")
' objEmail.From = "bill.burke@atosorigin.com"
' objEmail.To = "DLUSO-DFW-NT-ADMIN-ARL@atosorigin.com"
' objEmail.Subject = "Workstation SUS Update Notification "
' objEmail.Textbody = "System Name" & vbTab & "Date" & vbTab & "Time" & vbTab &
"Success/Fail" & vbCrLf &_
' strComputerName & vbTab & strCurrentDate & vbTab & strCurrentTime & vbTab
& "Success"
' objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"usdax003.arl.us.int.atosorigin.com"
' objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' objEmail.Configuration.Fields.Update
' objEmail.Send

' The following two lines write an event in the Application Log file of the
'local computer (the system logging *in*)
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent eventSUCCESS, "Script to configure SUS has completed
successfully." , "\\" & strComputerName

' Create and destroy information dialog box for the end user notifying them
' that the installation has completed.
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup("AO's Windows Update Service has been installed on your
system. " & vbCrLf & vbCrLf &_
"The installation process is complete. " & vbCrLf & vbCrLf & "(This message box
will close itself in ten seconds...) ", _
10, " AO's Windows Update Service",0 + 64)
End If

WScript.Sleep(1000)

WScript.Quit

'******************************************
'******************************************

Re: Call script from within another script fails by Torgeir

Torgeir
Tue Feb 10 08:52:08 CST 2004

Bill wrote:

> I have two scripts that run correctly by themselves but when I call the second
> from within the first the process does not occur. I cannot read the error - the
> cmd box goes away too quickly.
>
> The first script will be called from the user logon script. The second will be
> run with elevated privileges and is called by the first. As I said above, each
> run correctly alone but fail when run together.
>
> When these scripts are run together, the process gets to the first message box
> in the second script then fails. I have marked with a row of "+" signs where
> the second script fails. I have run this script as a domain admin, local admin
> and reqular user.

Hi

Maybe not related to your problem, but I see you are using runas.exe and
SendKeys to obtain elevated privileges. I think I would have tried to get
one of the Runas wrapper utilities in the link below to work instead:

http://groups.google.com/groups?selm=3FE0B42C.773CA875%40hydro.com


--
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