Psexec is not running an EXE program remotely - psexec

Check everywhere for a reason but nothing I found matches my specific problem. I have a program in C:\somefoldername\anothersubdirectory\andanother\ of the remote pc that I try to run using PSEXEC but it does not take. PSEXEC just does not want to run anything for me. Now if I run a ping or tasklist via psexec, it works, though obviously this is in PATH.
So I am putting in:
PSEXEC \\pcname C:\somefoldername\anothersubdirectory\andanother\program.exe
and nothing happens.
I even wrote a batch script that I tried running in two different ways.
Script is just:
#ECHO OFF
C:\somefoldername\anothersubdirectory\andanother\program.exe
EXIT
and I had it copied to the remote pc's main directory (maybe I need to put it in a folder) and then I tried running C:\batch.bat using:
PSEXEC \\pcname C:\batch.bat
I also tries running:
PSEXEC \\pcname -c \\servername\batch.bat
so it copies it over to PATH.
Neither worked.
Does any program I try to run via PSEXEC have to be in the remote pc's path?
I do have to admit that I have not done running an EXE remotely, but I have written lengthier scripts using psexec that use batch file on a server without any hiccups.
What is weird to is that the program I run has parameters and I task that runs through it, so I first taskkill it remotely, then I PSEXEC the SAME EXACT EXE as:
psexec \\pcname C:\...\program.exe -a -few -parameters ODBC
and that works. When I try to open just program.exe on its own, nope doesn't take.
I also did try psexecing iexplore.exe and that didn't work either.

So gotta use the -i option. In addition to that, gotta use -p + -u or -s to load system hardware dependent gui. This is why large portions of the gui was missing, or I assume why.

Can you please try this format
psexec \\machineName -u username -p password /accepteula -h cmd /c
C://somefoldername//anothersubdirectory//andanother//program.exe >>log.txt
More Clearly
Download the PSEXEC tool zip file in your user machine and unzip it.
Open command prompt and go to the psexec path.
In my machine it is: D:\PsTools
Run following command line
Syntax:
D:\PsTools> psexec \\ip_address -u username -p Password cmd /c executablename arguments >> test.log

Related

Input to psexec command

I am trying to run a batch file which is placed in a remote windows server from my local system.
For that I am using psexec command as shown: psexec \\ip address -u user\username -p password cmd /c "path to batch file". This is executing same way as it executes on remote windows server. but at some point we have to press Q on the command prompt to get to next line on the batch file.
this is how it looks:
on Remote system
But I am unable to press Q on my local psexec command prompt, this is how it looks:
on my local system
is there a way to take key inputs for psexec command?
Thanks in advance.
I tried providing -accepteula option and also pipe it with powershell and try running it.
But no luck on that.

psexec command runs locally instead of remotely

I am trying to use psexec to download an installer and then execute the installer on a remote VM, but the command passed to psexec runs locally instead of remotely
When I run
PS > psexec \\RemoteVmName -u VmAdminUsername -p VmAdminPassword powershell (New-Object System.Net.WebClient).DownloadFile("http://ServerAddress:8080/MyInstaller.msi", "C:/installer.msi")
Expected Behavior
File gets downloaded to C:/installer.msi on the remote machine
Observed Behavior
File gets downloaded to C:/installer.msi on the local machine, the machine where psexec is being called from
Running psexec into a powershell prompt and then calling the download file method gets the desired behavior, but I need this to run without manual steps.
Works Manually
PS > psexec \\RemoteVmName -u VmAdminUsername -p VmAdminPassword powershell
PS > (New-Object System.Net.WebClient).DownloadFile("http://ServerAddress:8080/MyInstaller.msi", "C:/installer.msi")
That gets the installer on the remote machine but requires human input. I need to do the same without human input.
Using the -i and -h flags are not helping.

PsExec: Win7-to-Win7 Access Denied (psexesvc remains)

I have a problem, and the Internet doesn't seem to have a solution, so maybe someone here can help.
I'm trying to start a command-line prompt on a remote machine using PsExec, but I keep getting an "Access is Denied" error. Both my local and the remote machine are running Windows 7 Enterprise (local: x64, remote x86) and I'm using PsExec 1.98. I use the following command:
psexec \\remote -u domain\user -p password -i -d cmd.exe
I have also tried other commands (such as using -s, -h, etc.), it doesn't seem to make a difference. I have access to the admin$ share of the remote machine from my local one. The Event Viewer tells me that a logon (and logoff) occurs on the remote machine.
Also, PsExec creates the PSEXESVC.EXE in the windows directory, but does not delete it!
Interestingly, the same command works just fine on a Win-7-Professional (x64) and it also works perfectly fine in reverse (i.e. when executed from the remote machine to start cmd on the local one). Deactivating anti-virus and firewall on the remote machine did not make a difference. I cannot deactivate it on the local one, but I have my doubts that the error is caused there.
Does anyone have any ideas?
Bit late, I know, but I've just been trying to solve this too. Turns out it has to do with security levels / user access levels.
I was trying to run psexec from a command prompt on a local PC and had started the command prompt by right clicking and choosing "Run as administrator". Then I'd run the psexec command targetting a remote server and specify a domain admin account for the -u parameter.
However, my local account only had administrative privileges on the local machine, not the remote one and choosing "run as administrator" doesn't actually mean "run as domain administrator"! (Obviously, duh!).
So, in effect, what was happening was that it was trying to run my main command as a domain admin on the remote but the psexec part was being run as my (non-admin) domain user account - which didn't have the appropriate permissions on the server.
Solution: Instead of starting a command prompt as above use the runas command.
eg: Start -> Run -> runas /user:domain\administrator cmd
then run your psexec command and you won't need the -u flag
or, from inside a normal command prompt you could do this instead:
runas /user:domain\administrator "psexec \\remote cmd"
after trying everything and still not getting any good results I figured what was the issue at least in my case. I had a machine with logged in domain account(not domain admin but at least local to the machine admin) and few other machines that had local accounts with admin rights. Psexec worked on all of them but was not working on my machine using domain account with local admin rights. On the machine that psexec worked with the local admin account I logged in with my domain account with local admin rights - and to no surprise it did not work.
So bottom line is that you should start the psexec call to the remote server with admin account local to the machine that you are sending the call from.
Better yet just insert this before your psexec string which will go now in double quotes
runas /user: ""
this way psexec will run but using the local admin account and no need to actually log in with the local admin account
The only way which works for me was to set the network credentials:
cmdkey /list:%DOMAIN% | find "%DOMAIN_USER%" >NUL || cmdkey /add:%DOMAIN% /user:%DOMAIN%\%DOMAIN_USER% /pass:%DOMAIN_USER_PWD% >>%LOGFILE% 2>>&1
Runas was not possible with local shares and other permissions.
I know this is really late, however as it's the first search in Google I am going to reply.
Through much research I found that you need to have the username and password BEFORE the system name, so instead of:
psexec \\remote -u domain\user -p password -i -d cmd.exe
Do it this way:
psexec -u domain\user -p password -i -d \\remote cmd.exe
I wanted to install a program from a server share (the PC I'm working on, I was logged in as domain administrator) remotely on "RemotePC".
PsExec worked on RemotePC with "local" programs (local to "RemotePC") like cmd.exe:
PsExec.exe \\RemotePC cmd.exe
Initially, my full command looked like this:
PsExec.exe \\RemotePC "\\server\sharename\path to program\setup.exe" /s /v"/qn IP_SERVER=192.168.1.10 PORT=112 INSTALLDIR=\"%ProgramFiles(x86)%\path\ \" "
But the setup from the server share didn't start.
Error message:
PsExec could not start \\server\sharename\path to program\setup.exe on RemotePC
Access is denied
I tried much of the solutions I found here and on other websites like adding PsExec -u administrator -p password and using cmd.exe /c, but it didn't work.
Finally I found a working command (the /s with extra quotes around the commandline did the trick):
PsExec.exe \\RemotePC -u administrator -p AdminPassword cmd.exe /s /c " commandline "
The full working command looks like this:
PsExec.exe \\RemotePC -u administrator -p AdminPassword cmd.exe /s /c " "\\server\sharename\path to program\setup.exe" /s /v"/qn IP_SERVER=192.168.1.10 PORT=112 INSTALLDIR=\"%ProgramFiles(x86)%\path\ \" " "

psexec cannot kill cmd.exe & psexec.exe after execute

i had used a batch cmd (xxx.bat) to execute a psexec function as follows:
C:\psexec.exe \192.168.xxx.xx -u server1\admin -p password C:\xxx.bat
the above batch file can run successfully to remote execute file.
but i found that there are many cmd.exe and psexec.exe process in task manager, that the batch file cannot kill process after execute.
do you know how to kill cmd.exe and psexec.exe process after execute ?
thanks
Joe
I'm sure there's a better way, but personally, I do this using pskill, e.g.:
pskill.exe \\\\192.168.x.x -u user -p pass -t <imagename>
You can find the name of the executable that you want to kill using the pslist command, also in the pstools toolset.

Does psexec support input redirection?

I am trying to control a remote Python script via psexec, which reads commands from stdin, but I need to redirect psexec's input since psexec itself will be launched from another program. However, I have no luck making psexec accept redirected input. Is it supposed to work at all?
An example of what I'm trying to do, where input is a file containing input to the remote script:
psexec \\mymachine python c:\script.py < input
Here's one way I was able to kinda accomplish what you're after:
PsExec.exe -d \\\\192.168.1.1 cmd /k "echo list volume | diskpart"
This would pass the commands "list volume" to the diskpart command. Additionally you can also try using cmd like this for you example:
PsExec.exe -d \\\\192.168.1.1 cmd /k "python c:\script.py < input"