PSexec on remote machine hangs running from Teamcity - teamcity

I'm running TeamCity version 7.1.4 with a step that uses PSEXEC in order to run batch file on a remote machine. The batch file should extract files and deploy them.
Running the PSEXEC from command prompt completes the task.
Running from team city i always get the following hang:
PsExec v1.98 - Execute processes remotely [12:19:34]Copyright (C)
2001-2010 Mark Russinovich [12:19:34]Sysinternals -
www.sysinternals.com

It hangs because PsExec shows a window to accept the End User Agreement.
I solved adding the
-accepteula
switch to the command.
This flag suppresses the display of the license dialog.
Read Using PsExec for full command line parameters.

Related

PSEXEC returning garbage result. Why?

I want to run a script on a remote windows 2008 server using PSEXEC of PSTOOLs..
I have installed PSTOOLs on my local machine and can run the PSEXEC command successfully as well. I connect to the remote server through it and it even picks up the script placed there. However, all I get is some sort of garbage values. And after that it states that the intended network is no longer available, which it is because I can see it and access it through the GUI.
I must mention that when I execute that script manually in the remote server it works fine. I am using windows remote desktop utility to connect to the server.
Am I using PSEXEC the correct way? Or is the intended function of PSEXEC the same as what I am trying to do?
First you should have a look at the help page
You must use -w to specify the remote working dir, and you can't call a .bat directly, you have to call cmd.exe. So try this
psexec \\remoteserver -w "c:\users\admin\desktop\" cmd.exe /c youbatch.bat

run command as administrator on remote windows machine

Situation: Running the bat file on windows machine:
1. When I double click the bat file: Bat running is failed.
2. When I right click on bat file and run as administrator: Bat run is successful.
Now I have to run this bat file successfully from remote machine.
What I did:
1. Installed freeSSDd on remote machine and configured administrator user on freeSSHd to access shell and SFTP.
2. Now I am able to login to the remote machine using putty.
Problem:
I am not able to run the bat file successfully. How can I achieve this?
I also used runas /savecred /user:administrator C:/install.bat, but It didn't helped.
There is a way to get this working without any 3rd party software.
You have to create a task on the remote machine using the windows task scheduler which simply executes the desired command. There is an option where you can tell the scheruler to run a bat with a specific account. Enter an admin account and the password and check the "run with highest privileges" box. Leave "Triggers" empty, go to "Settings" and check the "Allow task to be run on demand" box. That's it!
Now when you want to run your file from a different location do
SCHTASKS /RUN /S <RemoteServerName> /U username /P password /TN "<task name>"
If you don't want to enter username and password each time you can adept the user policy (e.g. add the calling machine to the trusted list of the server).
If you have installed an ssh daemon, then you can run your BAT in a remote shell, but you remote shell may open up in something other than CMD.COM. I use cygwin to set up sshd and then from a remote machine, if I ssh in to run a command, it is using cygwin's bash. I can run a BAT file, but need to call CMD first:
ssh WINDOWS_SERVER "cmd /C D:\PATH_TO_BAT\BATCHFILE.BAT"
But there are some pieces missing here. I looked briefly at the Freesshd page and saw only graphical interfaces. Does freesshd support remote command execution, or just secure fire transfer? And what sort of shell get executed on the windows server when you run it?
cygwin is an entire Linux subsystem that runs under Windows and includes an sshd server, but might be a bit much for someone starting out: https://cygwin.com/
\n makes a powershell remote server that listens on port 22 (ssh) and dumps you into a powershell prompt, you can then use my steps above to call CMD from powershell, versus a bash shell.
http://www.powershellserver.com/

Launch Notepad.exe using PsExec sysinternal tool

I am trying to launch notepad.exe on remote server A from local server B.
below is the command which works fine and I could see notepad.exe process on Task Manager however when I physically remote login to server I do not see notepad launched (GUI).
C:\Windows\System32>D:\SysInternals\psexec.exe \\serverB
-u Domain\user1 -p passXX -i -d notepad.exe
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
notepad.exe started on serverB with process ID 3328.
How would I see notepad GUI when logged in ?
is serverB a terminal server ? if so you have to specify the user's session number, otherwise notepad will be opened in the console (session 0).
you can use for example query session to get the active session on you server :
query session /server:serverB user1
then pass the session number to -i parameter :
psexec \\serverB -u domain\user1 -i 2 notepad.exe
where 2 is the session of user1

can't start notepad on remote machine using psexec

I need execute some script in remote computer, I try to start notepad. I use psexec, this command
psexec -e -i 1 \\localhost -u domain\user -p password cmd /c notepad.exe
successfully opens notepad on my local machine, but doesn't do it on remote.
I can't see any error, output is the same as I see after executing on local machine:
PsExec v2.0 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
What could be a reason I can't execute notepad successfully on remote machine?
To start notepad on remote machine using psexec:
psexec \\RemoteserverHOSTNAMEorIPADDRESS -u domain\user -p password -d -i cmd /c notepad.exe
For more information.....PsExec

PsExec hangs when executing batch file in bamboo continous integration server

I have a batch file on my bamboo server, that starts another batch file on an remote computer trough PsExec. If I double click the batch file on the bamboo sever everything is working fine, the batch file on the remote computer starts and PsExec exites with error code 0.
But if I start bamboo then PsExec hangs itself and the batch file on the remote computer don't start.
C:\PsTools>PsExec.exe \\<remote server> -u <user> -p <password> -s -i "C:\batchfile.bat"
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
This is my output and where PsExec hangs.
I don't understand why it hangs only when bamboo starts the batch.
Hope someone can help me
[ Program output lost when passed through PsExec ]
there's a bug in psexec and it does redirects correctly when is called by everything different by cmd. You have few more options to start a process on remote machine:
1. http://feldkir.ch/xcmd.htm - it cannot be run on localhost
2. WMIC - also cannot be used on localhost , when host and and user/pass are given
2. SCHTASKS
This is an old question but maybe somebody has the same problem.
The first time you run psexec an eula dialog is shown. In order to avoid bamboo hanging with this dialog you may try the argument \accepteula. For instance:
PsExec.exe \\<remote server> -u <user> -p <password> -s -i "C:\batchfile.bat" -accepteula

Resources