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.
Related
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.
I am having a virtual machine which i am using it as a server. I have my local machine as a client.
I have a windows batch file in the virtual machine, a.k.a the server which has a series of command.
I try to run the batch file from the client through psexec. I can access the file and execute the file. But not all the commands are executed. They need administrative privileges.
The command that i use is
psexec \virtualmachinename -s -u domainname\username -p PASSWORD c:\foldername\batchfile.bat
NOTE 1: I cannot select the option of "Run as Administrator" in the properties of the batch file. The check box is grayed, that means i cannot select/deselect anything.
NOTE 2: I have given the user of my virtual machine full administrative privileges.
Any insight or possible solutions will be of great help.
If the account you are logging into with is an Administrator then your code should be working.
However the first thing I would try would be to add runas /user:administrator ie:
psexec \\virtualmachinename -u domainname\username -p PASSWORD cmd && runas /user:administrator && c:\foldername\batchfile.bat
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
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.
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"