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

1 Answer 1

0

psexec can do that:

psexec \\Test-Server-01 -u User -p Pass d:\local\path\to\CC.exe
5
  • 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
    Commented Aug 4, 2017 at 11:38
  • If you wish to use other credentials than the network ones, nothing prevents you from using psexec with the runas command.
    – harrymc
    Commented Aug 4, 2017 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
    Commented Aug 4, 2017 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
    Commented Aug 7, 2017 at 9: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
    Commented Aug 7, 2017 at 9:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .