As part of as our Team Build MSBuild script, we have a deployment batch file which I need to execute on a remote server:
<Exec Command="psexec -accepteula \\servername D:\Build_Drop\DeploySites.bat "/>
I can confirm it is not permissions or firewall: if the bat command is changed to run iisreset or calc.exe for example, the command will work.
I have tried -s and >nul flags, and also wrapping the batch file in a call to cmd. I have tried with and without quotes around the bat cmd.
All the options I have tried will work fine from the cmd line on the build server, but none will work from within the build script itself.
Any ideas?
Adding a -i parameter to psexec seems to have worked.
Oddly, we now get the error message:
The command "psexec -accepteula \\server -i cmd /c "D:\Build_Drop\DeploySites.bat"" exited with code 5. Please verify that you have sufficient rights to run this command.
But the command does actually work
Related
I need to create a .bat to put together with my setup system to install a network driver, but I have some difficulties in creating the bat.
This .bat needs:
execute a cmd with administrator privileges
run this command: netcfg.exe -v -l networkbll_lwf.inf -c s -i nt_networkbll
exit
The folder for all files location is: c:\Windows\System\Drivers.
You might have to use another batch file first to launch the second with admin rights.
In the first use
runas /noprofile /user:mymachine\administrator batchfilename.bat
PAUSE
and write the needed command in another bat file
Its almost certain that HTA files are obsolete, but i've found that they are much better than net send / msg.
I'm trying to run a HTA file on a remote machine using PSTools, but instead of it running, it brings back a broken window:
Running the HTA file using CMD (locally) works perfectly though.
My PsExec line:
PsExec.exe -accepteula -i -d \\itwall cmd 'mstha \\intranet\Downloads\VisitorSystemNewMessage.hta asd'
I even tried to run the HTA from a Batch file, but the exact same thing happens.
Any ideas?
It's because the account running the command cannot interact with the session of the remote user.
Use the -s switch to run the HTA using the system account of the remote computer.
Also, you shouldn't need to run cmd. You should be able to just specify mshta.exe then your arguments.
PsExec.exe -accepteula -s -i -d \\itwall mshta.exe \\intranet\Downloads\VisitorSystemNewMessage.hta asd
Edit: To illustrate that this is not an HTA issue. Run the following command:
PsExec.exe -accepteula -i -d \\itwall notepad.exe
Notice you'll have the same black window showing.
I need to create a batch file that will open cmd.exe (as a administrator) with these lines:
cd C:\Program Files\Putty
cd C:\Program Files\Putty>psftp -i XXXXXXXXX.ppk xxxx_test#111.111.111.11 -b C:\UPLOAD\upload.ftp
Can anyone help me?
DoStuff.bat
#echo off
runas /user:%USERDOMAIN%\%USERNAME% "cmd.exe /K \"cd C:\Program Files\Putty\" & psftp -i XXXXXXXXX.ppk xxxx_test#111.111.111.11 -b C:\UPLOAD\upload.ftp"
runas will let you run a command as Administrator (you may need to change the domain/user to match your system, and enter a password).
Running cmd.exe /K will run the following commands.
The quotes around the commands need to be escaped with \"
I'm having a hard time seeing the difficulty.
Can you explain what you tried, and why it didn't work?
Following is my msdeploy command to copy files from one server to another (server1 to server2) successfully:
MSDeploy.exe -source:contentPath="C:\inetpub\wwwroot\dist",computerName="https://server1:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXX",authtype="Basic" -allowUntrusted -dest:contentPath='C:\Builds\dist',computerName="https://server2:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXXX",authtype="Basic",includeAcls="False" -verb:sync -allowUntrusted
I have one more similar command exactly as above to transfer files between server3 and server4 as well which is working successfully from command prompt. Whereas when i put one of these commands or both in a .bat file, getting the following error:
Below is the exact content of my batch file:
#ECHO OFF
CD C:\Program Files\IIS\Microsoft Web Deploy V3
MSDeploy.exe -source:contentPath="C:\inetpub\wwwroot\dist",computerName="https://server1:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXX",authtype="Basic" -allowUntrusted -dest:contentPath='C:\Builds\dist',computerName="https://server2:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXXX",authtype="Basic",includeAcls="False" -verb:sync -allowUntrusted
MSDeploy.exe -source:contentPath="C:\inetpub\wwwroot\dist",computerName="https://server3:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXX",authtype="Basic" -allowUntrusted -dest:contentPath='C:\Builds\dist',computerName="https://server4:8172/MSDeploy.axd",username="administrator",password="XXXXXXXXXX",authtype="Basic",includeAcls="False" -verb:sync -allowUntrusted
I tried running as an administrator , still the same problem. To my surprise the exact same commands with some other servers are working fine from the .bat file as well.
Executing the batch file with cmd /c is working. Usually cmd /c needs to be used to return control to the bat file even though there are fatal errors. Don't know the exact reason why only this works because there are no fatal errors in my case.
check this for more information A .bat File, "Call" or Not to "Call", That is the
I have a batch file called test.bat in server which contains 2 call batch command inside it.
I am running this test.bat from another server using psexec command
The first call batch file command working fine however when it goes to next call batch command its throwing error ".bat exited with error code 0."
Actually what the second command does is that something like below
call D:\abc\def\ghi\test2.bat test >>test.log
I am not sure why its failing in this line. Is it due to write permission?
Please advise...
Error code 0 actually means success. This is psexec reporting that the remote execution completed successfully.
Finally I resolved by the below command and write the log in my local server where I am running the psexec command
psexec -u username -p password \\testserver "c:\test\test.bat" 1>Outputlog