I am trying to execute following command
psexec \\x.x.x.x -d -c -f cmd.exe /c d:\test\hello.bat
It runs fine and gives output
cmd.exe started on x.x.x.x with process ID 106084.
But when I login on x.x.x.x I can find the process ID but no visible batch file is launched. It runs in background.
Batch file
echo "Hello"
pause
Please tell me how to see the command window launched on x.x.x.x
Thanks in advance
I think you can look at the Session Id for your current user and pass it as parameter with -i For example:
PsExec.exe -s -d -i 2 c:\temp\MyServer MyConsoleApp.exe
To look at the current Session Id you can run query session
Sometimes the Session Id is 2 for the active user you want to start process for, so try looking for your correct Session Id and use it with -i parameter.
Try one of those:
psexec \\server -u xxx-p xxxx /accepteula -i 1 -d cmd.exe /K "cd d:\test && call hello.bat"
psexec \\server -u xxx -p xxxx /accepteula -i 1 -d d:\test\hello.bat
Alex K. is correct. Specifically, remove the "-d", which tells PsExec "Don't wait for process to terminate (non-interactive)". In fact, if you run the sample batch file above, which includes "pause", the cmd process will continue to run on the remote host (invisible to the remote host's GUI, since it's done via PSExec) until you kill that process.
PsExec.exe -s -i 2 C:\path_to_exe.exe
This need to check with the session ID variable (-s & -i)
Related
I am using PSTools to remotely running the application in Windows machine using the command
PsExec.exe \Machine-i 1 -u Username -p Password -d /accepteula
C:\Test\PsexecConsole.exe
My question is what is the 1 means in the command?
As stated in the documentation of the PsExec.exe application the -i switch is used to identify the session on the remote system:
-i Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session.
I want to run some commands on the remote machine. I am using psexec.exe in my application, when I try to run some command using -h and -s arguments as mentioned in the below command.
C:\psexec.exe -accepteula \\IPAddress -h -u "Username" -p pwd -s netstat -bno
When we provide a valid username and password it works with provided credentials, but when we provide username and password which is not valid it picks up -s and works I have done some research on -s it says -s = Run the remote process in the System account.
What exactly -s command do, when running above mentioned command on a particular remote machine with the arguments like -h and -s together is user passed Username and Password will be preferred over -s?
With -s your command is executed with the System account. The System account is a special Windows account used to run core Windows services (more info here and here); this account also has special privileges, for example access to registry keys that is denied to all other accounts.
As you can read in the linked docs:
This account does not have a password
so you don't have to specify a password when using the System account.
This is how PsExec works:
When you add the -s parameter the command is executed with the System account, so -u and -p parameters are ignored.
If you specify -h (but not -s), then account and password (-u and -p) are used to connect and execute the process with the account's elevated token (if available), so they must be correct.
If you specify -h together with -s then account and password (-u and -p) will NOT be used to connect, since the command will be executed with the System account anyway.
You can double check this behavior launching a program on a remote server and looking at the task manager of the remote machine: you will see that, using -s, the program will run under the System account, otherwise it will run under the user specified with -u.
For example if you run notepad with this command:
psexec \\remote_server -u domain\user -p correct_password -d -i -s cmd /c notepad.exe
or with this command:
psexec \\remote_server -u domain\user -p correct_password -d -i -s -h cmd /c notepad.exe
or with this command:
psexec \\remote_server -u domain\user -p wrong_password -d -i -s -h cmd /c notepad.exe
in all these three cases notepad is executed under the System account:
I have a task in which I need to launch multiple manual backups and need each to be launched in a separate window so I do not have to wait for each one to complete.
I am pulling a list of servers from a txt file and just need each instance to be in its own window.
The command line is:
PSEXEC #servers.txt -s -w "C:\Program Files\Tivoli\TSM\baclient" "C:\Program Files\Tivoli\TSM\baclient\dsmc.exe" "Incremental"
You can use Windows' start command.
If you just don't want to wait for the completion of each single issued command, you can use psexec's -d option:
-d Don't wait for process to terminate (non-interactive).
Thanks to Michael for posting - I added the -d option to have it continue on without waiting for a response of which it did not need.
PSEXEC #servers.txt -s -w "C:\Program Files\Tivoli\TSM\baclient" -d "C:\Program Files\Tivoli\TSM\baclient\dsmc.exe" "Incremental"
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 tried command like below. But can't see server time.
psexec \\SERVER_NAME -i -u USERNAME -p PWD "C:\WINDOWS\system32\cmd.exe /c time /t"
Or is there any alternative? Thanks.
net time \\SERVER_NAME
Ps. This question really belongs at ServerFault.
I have about 100 servers in my company. Once i had to check system time on all servers.
The solution was:
psexec -d -i cmd /c nettime.bat
content of nettime.bat file :
#echo off
net time \\server01 >>c:\1.txt
net time \\server02 >>c:\1.txt
net time \\server03 >>c:\1.txt