0

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:[email protected] "D:\Program Files (x86)\CruiseControl.NET\server\ccnet.exe"
PAUSE
Mr.B
  • 113
  • 1
  • 2
  • 7

1 Answers1

0

psexec can do that:

psexec \\Test-Server-01 -u User -p Pass d:\local\path\to\CC.exe
harrymc
  • 455,459
  • 31
  • 526
  • 924
  • Apologizes my explanation may not be clear enough I will adjust it. In the above example you have provided. User & Pass are the Servers Username and Password correct? While I need do need to this part in order to access the server, I also need to "Run as different user" when using the "d:\local\path\to\CC.exe" – Mr.B Aug 04 '17 at 11:38
  • If you wish to use other credentials than the network ones, nothing prevents you from using psexec with the [runas command](https://technet.microsoft.com/en-us/library/bb490994.aspx). – harrymc Aug 04 '17 at 11:43
  • Great, Will do some testing before updating with my result & accepting your answer this snippet looks exactly what I need, Thank-you much appreciated. – Mr.B Aug 04 '17 at 11:47
  • I've tried combining runas and psexec and unfortunately I'm having little success. could you provide an example? I've updated my initial post to reflect this. – Mr.B Aug 07 '17 at 09:33
  • You might need to use for psexec the argument of `-h`, or else use `-s` (might require administrator user/password). If problems, please add to the post your tests and exact results. – harrymc Aug 07 '17 at 09:40