I'm trying to call PsExec from a WScript.Shell Object in the form posted below (but am definitely open to alternatives).
Set oShell = CreateObject("WScript.Shell")
oShell.Run "cmd.exe /C C:\Users\NOT_Administrator\Desktop\PsExec.exe \\192.168.10.5 -u Administrator -p PASSWORD cmd /c ""C:\Windows\Launch_Bat.exe"""
Please note that for PsExec to ever succeed a PASSWORD is required.
The thing about this is that because the initial cmd.exe from oShell.Run is being launched from a non-administrative user, PsExec inherits those lack of privileges and ultimately fails to connect giving the error "Access is Denied." I concluded this after reading and testing PsExec between a non-administrative command prompt (no VBScript involved) in which it failed, and from an administrative Command Prompt from where it succeeded.
So my question is, is it possible to make VBScript launch either cmd.exe as an Administrator (preferably in the form posted above) natively within the script, or force the PsExec portion to use the priviliges passed in as administrative account credentials?
Additionally, I tried 2 methods posted below (both are in a different form from the one I desire):
https://gallery.technet.microsoft.com/scriptcenter/9bda53d7-ec2e-4bc2-8e97-4487233bc55b
set WshShell = WScript.CreateObject("WScript.Shell") PASSW = "PASSWORD" WshShell.run "runas /user:Administrator %comspec%" WScript.Sleep 1000 WshShell.SendKeys PASSW WScript.Sleep 1000 WshShell.SendKeys "{ENTER}"But this closed then opened up an administrative Command Prompt, but I couldn't make the script pass anything into the new prompt.
-
If WScript.Arguments.Length = 0 Then Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "wscript.exe", Chr(34) & _ WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1 Else WScript.Echo "This code is ran as an elevated user, ie. 'Administrator'" End IfBut this opens up an echo dialog box, but when I put it at the head of my script, it simply made it loop infinitely. It also requires me to input the password which I do not mind. I prefer not to, but if I must I will. I know that
runasdoesn't have an explicit flag to pass in the password unfortunately although you can use set_credentials.