southboyj Posted January 4, 2010 Share Posted January 4, 2010 I am trying to execute a remote file using adminstrative credentials. Variables work with other scripts. PSEXEC resides in the same folder as the script and the FILENAME.CMD resdies on the remote computer that the user account has access to. I have tried several combinations of syntax without success. Any advice would be greatly appriciated. Thanks... ;Variables $UserID = InputBox ("User Name", "Enter User name", "", "") $Password = InputBox ("Password", "Enter Password","", "X") $Domain = InputBox ("Domain", "Enter Domain","" , "") $ComputerName = InputBox ("Computer Name", "Enter Computer Name","", "") RunAs ($UserID, $Domain, $Password, 0, @ComSpec & " /c " & @ScriptDir & "\PSEXEC.EXE \\" & $Computername "c:\FILENAME.cmd" & "-u" $UserID & "-p" $Password") Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 4, 2010 Share Posted January 4, 2010 (edited) I am trying to execute a remote file using adminstrative credentials. Variables work with other scripts. PSEXEC resides in the same folder as the script and the FILENAME.CMD resdies on the remote computer that the user account has access to. I have tried several combinations of syntax without success. Any advice would be greatly appriciated. Thanks... ;Variables $UserID = InputBox ("User Name", "Enter User name", "", "") $Password = InputBox ("Password", "Enter Password","", "X") $Domain = InputBox ("Domain", "Enter Domain","" , "") $ComputerName = InputBox ("Computer Name", "Enter Computer Name","", "") RunAs ($UserID, $Domain, $Password, 0, @ComSpec & " /c " & @ScriptDir & "\PSEXEC.EXE \\" & $Computername "c:\FILENAME.cmd" & "-u" $UserID & "-p" $Password") Try a couple of tweaks: 1. @ScriptDir might have spaces in it, so quote the executable path. 2. Dropped a space before batch file path. 3. Dropped spaces between parameters. 4. No ampersand for appending $Password. 5. Stray " after $Password RunAs($UserID, $Domain, $Password, 0, @ComSpec & ' /c "' & @ScriptDir & '\PSEXEC.EXE" \\' & $Computername & ' c:\FILENAME.cmd -u ' & $UserID & ' -p ' & $Password) I wonder also if you are confused about the context of the RunAs() account. Are you sure the same account is appropriate for running psexec and for psexec to use on the remote computer? If the local account running the script has rights to run psexec, then all you need might be: Run('"' & @ScriptDir & '\PSEXEC.EXE" \\' & $Computername & ' c:\FILENAME.cmd -u ' & $UserID & ' -p ' & $Password) The username\password would only be needed on the remote end. Edit: Oops. Fixed missing string formatting in Run functions per comments below. Edited January 5, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
southboyj Posted January 5, 2010 Author Share Posted January 5, 2010 Thanks for keeping me straight. You are absolutely correct....local user account has access to PCEXEC therefore no need to RunAs. However, when I copy & paste code, I get an error: Run(@ScriptDir & '\PSEXEC.EXE" \\' & $Computername ' c:\FILENAME.cmd -u ' $UserID & ' -p ' & $Password) Run(^ ERROR >Exit code: 1 Link to comment Share on other sites More sharing options...
tlman12 Posted January 5, 2010 Share Posted January 5, 2010 (edited) he forgot the & before $user and after $computername try this Run(@ScriptDir & '\PSEXEC.EXE" \\' & $Computername & ' c:\FILENAME.cmd -u ' & $UserID & ' -p ' & $Password) Edited January 5, 2010 by tlman12 Link to comment Share on other sites More sharing options...
southboyj Posted January 5, 2010 Author Share Posted January 5, 2010 Worked great. Thanks Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 5, 2010 Share Posted January 5, 2010 he forgot the & before $user and after $computername Oops. Also dropped the preceding '"' on the path (or " need removed after psexec.exe). Could also be: ShellExecute(@ScriptDir & '\PSEXEC.EXE', '\\' & $Computername & ' c:\FILENAME.cmd -u ' & $UserID & ' -p ' & $Password) Not tested. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now