Caveman's Blog

My commitment to learning.

PSExec: Remote command execution

leave a comment »

Ever wondered how to remotely execute a command on a remote machine. Here is what I had to deal with, leading to my research and a subsequent discovery of this powerful utility. We have this ASP.Net project that was getting deployed to the various in-house environments using Hudson, a continuous deployment tool. There was this requirement that the web.config had to be encrypted. In our project configuration setup, the files from the build (CI) server will be deployed/coped to various environments, however the web.config cannot be pre-encrypted, rather it has to be encrypted in the hosting environment.

I have created a batch file  that has to be executed on the deployed environment to be able to encrypt the web.config file. PSExec came to my rescue by being able to execute the batch file on the host environments from the continuous integration server. The account that is used to run Hudson should also have rights on the host machines to be able to run PSExec.

PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software. PsExec’s most powerful uses include launching interactive command-prompts on remote systems and remote-enabling tools like IpConfig that otherwise do not have the ability to show information about remote systems. [1]

Example 1:
psexec \\MACHINE_NAME c:\temp\encrypt.bat

Example 2: This is very useful when you have to perform am IISReset remote

Example: 3 - Explicitly pass user credentials

Example: 4 - Use this to encrypt the web.config settings after a deployment using Hudson
psexec aspnet_regiis -pef appSettings

I hope I made my point in showcasing a capability of this tool. Here is a good read about the inner working of psexec.

1. PSExec – by Mark Russinovich


Written by cavemansblog

September 15, 2009 at 3:33 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: