Hi
I need to send a CD out to some home users with software updates.
The updates need to run under the local admin account but there are 2
possible local admin passwords in use.

I need my script to attempt installation with the first admin password and
if this fails then use the second (and if for some reason the second fails
then to popup an error.
I've tried writing it like below but the errReturn doesn't seem to work and
the script just waits for the password input, it doesn't seem to get the
input automatically from SendKeys.

I know I can get round this by specifiying FALSE in my errReturn but if I
specifiy FALSE then errReturn will always be 0 so it will never attempt the
second admin password.

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set WshShell = CreateObject("WScript.Shell")
Set objStdOut = Wscript.StdOut

strCommandLine = "runas" & " " & ("/u:administrator c:\temp\go.bat")

errReturn = WshShell.Run(strCommandLine, 1, True)
Wscript.Sleep "300"
WshShell.SendKeys "password1~"
If errReturn = "0" Then
Wscript.Echo ""
Else
errReturn = WshShell.Run(strCommandLine, 1, True)
Wscript.Sleep "300"
WshShell.SendKeys "password2~"
If errReturn = "0" Then
Wscript.Echo
Else
DoPopup
End If
End If


Function DoPopup
Call WshShell.Popup("This computer has a non-standard Administrator
password. Cannot continue, please contact the helpdesk quoting this
message.", 0, "Error", 16)
End Function


Can anyone help at all, this has been driving me loopy all day! :)

Thanks
Steve

RE: errReturn RUNAS and SendKeys by sjw2k3

sjw2k3
Tue Sep 13 02:27:01 CDT 2005

Anybody?
Any ideas??

"sjw2k3" wrote:

> Hi
> I need to send a CD out to some home users with software updates.
> The updates need to run under the local admin account but there are 2
> possible local admin passwords in use.
>
> I need my script to attempt installation with the first admin password and
> if this fails then use the second (and if for some reason the second fails
> then to popup an error.
> I've tried writing it like below but the errReturn doesn't seem to work and
> the script just waits for the password input, it doesn't seem to get the
> input automatically from SendKeys.
>
> I know I can get round this by specifiying FALSE in my errReturn but if I
> specifiy FALSE then errReturn will always be 0 so it will never attempt the
> second admin password.
>
> strComputer = "."
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set WshShell = CreateObject("WScript.Shell")
> Set objStdOut = Wscript.StdOut
>
> strCommandLine = "runas" & " " & ("/u:administrator c:\temp\go.bat")
>
> errReturn = WshShell.Run(strCommandLine, 1, True)
> Wscript.Sleep "300"
> WshShell.SendKeys "password1~"
> If errReturn = "0" Then
> Wscript.Echo ""
> Else
> errReturn = WshShell.Run(strCommandLine, 1, True)
> Wscript.Sleep "300"
> WshShell.SendKeys "password2~"
> If errReturn = "0" Then
> Wscript.Echo
> Else
> DoPopup
> End If
> End If
>
>
> Function DoPopup
> Call WshShell.Popup("This computer has a non-standard Administrator
> password. Cannot continue, please contact the helpdesk quoting this
> message.", 0, "Error", 16)
> End Function
>
>
> Can anyone help at all, this has been driving me loopy all day! :)
>
> Thanks
> Steve