JuHwon
JuHwon

Reputation: 2063

automatic deploy via RDP script

I have to deploy my .NET software on several RDP Servers (MS Srv). There is no Networkshare available due to security reasons.

Is it possible to do this with a script (powershell) or something like this to automate this process?

At the moment i am

I'd like to make this process simpler somehow...

I only found this thread until now and i dont know if this is a help to me: Copy files to a remote server via RDP using a script Has anyone experiance with this topic?

Upvotes: 1

Views: 1432

Answers (2)

Mathias Mamsch
Mathias Mamsch

Reputation: 333

You can initiate an RDP Connection automatically by combining cmdkey.exe and mstsc.exe:

Store your credentials for the servers by executing:

cmdkey.exe /generic:servername /user:username /pass:pass

Afterwards you can automatically logon to the server by:

mstsc.exe /v:servername

You can also save your custom RDP settings to an rdp file by choosing "Save" inside the connection settings of mstsc. You can then initiate the connection by:

mstsc.exe myfile.rdp

The question now is, what exactly do you do to get the file to the remote computer. If you are able to get the file over the \tsclient share, then you might get lucky by either trying to use the option to execute a program after connecting to the RDP server. For this you can add the following two lines to your rdp file:

    remoteapplicationname:s:C:\windows\system32\cmd.exe
    remoteapplicationcmdline:s:C:\windows\system32\cmd.exe /C deployMyStuff.bat

Another option would be to find out the RDP session ID after connecting and try to execute a batch process on the remote machine using psexec from sysinternals. See an example for getting the active session here:

Selenium hover action with IE doesn't work if RDP never connected to Jenkins slaves

Then you might be able to start a process in the active session from your local PC using psexec from sysinternals:

    psexec \\servername -i %SESSION% -d CMD.exe /C mydeployment.bat

Upvotes: 0

Karl Harnagy
Karl Harnagy

Reputation: 727

RDP File transfer works through a fairly complicated tunneling process, where your computer ends up being exposed to the server as tsclient. It's not really feasible to script this because it involves interactive sessions.

Have you considered an automation tool? Inedo's BuildMaster can handle this file transfering with a breeze (and it's quite a bit more secure/robust than RDP). It'd be pretty trivial to set it up to build the ClickOnce project as well directly from your source control. And from what it sounds like, the free edition of BuildMaster would work more than fine for your requirements.

(Disclaimer: I work for Inedo)

Upvotes: 2

Related Questions