Tuesday, January 20, 2015

command line - Windows Batch File: Execute .exe on server with 'Run as different user'

I'm looking to create a batch file to execute restarting CruiseControl.Net's .exe on a server. There are two complications to this:



  • Firstly I need to access the server remotely

  • Secondly I need to run the .exe under "Run a different user"


I've seen some examples using PSEXEC to connect to the server, but this is running the bat file using the server connection credentials not running the exe as a different user.


For Example imagine the respective parts are as below:



  • Server Name : "Test-Server-01"

  • Server Username: "User1"

  • Server Password: "Password1"


  • exe location: "Test-Server-01\d$\CC.exe"


  • exe Username: "User"


Example:


\\\Test-Server-01 -c test.bat -u User1 -p Password1

This runs "test.bat" on the server "Test-Server-01" with server's username and password. I then need to expand this to run the application under "Run as different user"


Question:How could I go about achieving this result?


I'm currently working backwards from this by starting with the "Run as different user" and executing this bat file on the server. This correctly starts the ccnet.exe but under the wrong folder.


CD "/D D:\Program Files (x86)\CruiseControl.NET\server"
RUNAS /user:user@company.com "D:\Program Files (x86)\CruiseControl.NET\server\ccnet.exe"
PAUSE

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...