1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| setupFile = "c:\Test.bat" '<-----application to runas [!]
hardcodedUsername = "domaine\user" '<----not nessesary, can be used if no scriptparameters were provided
hardcodedPassword = "password" '<----not nessesary, can be used if no scriptparameters were provided
'Read arguments...
'------------------------------------------------------
sUsername = Null
sPassword = Null
Set Named = WScript.Arguments.Named
If Named.Exists("u") Then
sUsername = Named.Item("u")
Else sUsername = hardcodedUsername
End If
If Named.Exists("p") Then
sPassword = Named.Item("p")
Else sPassword = hardcodedPassword
End If
set objShell = CreateObject("Wscript.Shell")
objShell.run("runas.exe /noprofile /u:" & sUsername & " "&Chr(34)&"\"&Chr(34)& _
setupFile &"\" &Chr(34)&Chr(34))
WScript.Sleep 600 '<----must be the max. amount of second it takes to to open the Runas: "enter password" window
objShell.AppActivate "runas.exe"
If objShell.AppActivate("runas.exe") then _
objShell.Sendkeys sPassword &"~" '<--- auto fill-in the password, and continues
set objShell = Nothing
Wscript.Quit |
Partager