PeopleSoft

Creating / Removing a Windows Service (PuTTY pageant)

May 18, 2008 · 1 Comment

How to Create / Remove a Windows Service

You should NOT do this for any Windows Service that you did not create yourself. In previous posts I mentioned that you could create a Windows Service to start for example the PAGENT.exe (PuTTY SSH Key Forwarding Agent) but I didn’t give any examples of how to create a windows service. I

There used to be a great web site that hosted homegrown Windows Utilities that individuals had written to perform some integral System Administration functions. This software was available for free and the site name changed over time to reflect the evolution of the software and the entities who hosted the site, etc. At some point software was added that wasn’t free but the spirit of the original web site remained intact to an extent. Eventually Microsoft came along and somehow took ownership of this site and the software that was available on it. Some of the original tools are still available for free but the original intent and spirit that the original site was created in disappeared.

Some of the tools there were so simple and that was a tribute to the elegance of the software code, the simplicity of use (most were command line driven and as anyone who knows me will attest I am still stuck to an extent in a command line world, basically because I personally feel that as you use GUI tools more and more and over a longer period of time you will forget the underlying architecture, the commands the GUI tools invoke and in a crunch you wouldn’t be able to perform the same functions without the GUI interface. That’s just a personal opnion that probably holds no merit but oh well it is my onion).

I can’t remember the original site name but over time it became sysinternals.com and now it is part of Microsoft’s TechNet:

http://technet.microsoft.com/en-us/sysinternals/default.aspx

I’ll give Microsoft this – its a pretty site. You’ll still see references to the old Sysinternals, the utilities are grouped by function. You’ll find information here on the various Windows Kernels and the history of the Sysinternals web site actually appears on the home page. Sysinternals was created in 1996 by Mark Russinovich and Bryce Cogswell to host their advanced system utilities and technial information. Microsoft acquired Sysinternals in July 2006. I believe I discovered their site a few weeks after it went up and I’ve continued to visit their site to retreive software updates, check for new utilities and tools and to read anything new that was posted. Some of their tools helped me out in some real jams. I discovered some very simple looking command line toosl that let me remotely execute commands on Windows Servers that became unaccessible at least to Telnet, Remote Desktop and/or via System Administration remote access like ‘Connect to Server’ in the Computer Management console.

The Process Explorer is one of the tools available here and it is an awesome way to walk through or explore all running processes on a windows machine. Plus, you can terminate (kill) processes via this tool which may be necessary in those rare situations where you can not end a task any other way.

It turns out the programs needed to create and set a Windows Application to run as a service are available as part of Microsoft’s Resource Kits. The two can be downloaded together in a zip file from:

http://www.tacktech.com/display.cfm?ttid=197

Find the line in the top third of the page that reads – You can download both files here srvany.zip and download the zip file. The zip file includes three files. The two you need srvany.exe and instsrv.exe to install the services and also srvany.wri which documents everything you can do with the program.

Note: Make sure the Services Manager is closed while you are running these DOS commands.

You will need to put these files into a directory named reskit. At a MS-DOS command prompt (Start->Run->cmd.exe), type the following command:

<path>\reskit\INSTSRV.EXE “Service Name” <path>\reskit\SRVANY.EXE

This creates the service in the Services Manager and the registry keys to setup what program to execute.

instsrv.exe command

Next open regedit.exe by: Start->Run->regedit.exe

I have to put the standard warning by Microsoft here – Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk! That statement means everything it says so if you have used Registry Editor in the past you should really have someone help you with this until you feel comfortable and have enough confidence to understand the criticality of what you doing and the associated risks.

Regedit - Run Box

Next navigate to this registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\service name

Registry Key - service name

From the Edit menu, click the Add Key and name it Parameters. Next from the Edit menu, click Add Value and type in this information:

Value Name: Application
Data Type: REG_SZ
String: <path>\<application.ext>
Service Test - Service

Now you can start your service from the Services Manager:

Services Manager - Service Test

With this same program you can remove the service also. Just run this command from the command prompt:

<path>\reskit\INSTSRV.EXE “Service Name” REMOVE

Remove Service

You should walk through the above example one time to familiarize yourself with the process and then do it for real. Instead of “Service Test” use a the name of the application you are creating a service entry for. To use PAGENT.EXE as an example I named my service – pagent – that way when I scroll through the service name listing in the Services Manager application I can find it very easily and it also is indicative of the real application’s name.

Note: If you use or have spaces and backslashes in your Service Name(s) you will not be able to remove the Service unless you specify the exact name as it appears in the Registry and which you can visually see via the Services Manager. The first image below shows an example of Service Names that contain both spaces and backslashes:

Service Manager Listing - Dev Server

The next image shows the individual Service and you’ll notice the name that Microsoft uses for the Service Name has underscores in it. Microsoft replaces the spaces and backslashes with underscore (_) characters and that is how you need to specify the service name when removing it.

Service box

Image of DOS commands used to remove services no longer needed:

Service Removal

I’ll paste a series of screen shots illustrating how to set up the PuTTY PAGEANT (Key Forwarding Agent) as a Windows Service:

Setting up the PuTTY Agent to run as a service is no big deal but in order to have it load your private key(s) when it starts requires using the parameter option of the Registry Key that is generated by the process. I’ve pasted an image below that shows the value of my parameter setting:

Pageant Parameter Settings

The value of the Parameters Registry Key in my instance is: D:\tools\pageant.exe D:\tools\psprod1dsa.ppk

I use D:\tools as the directory to hold all of my SSH programs and keys. The first part of the line is simply the location and name of the executable followed by a space and then the location (path) of my DSA private key file. You can load more than one private key by entering a space after each one and listing all of the private keys you need to load at start time.

Personally I use an Apple Mac Book Pro but I occasionally have a need to use a Windows application that doesn’t have a Mac OS X version or substitute so I boot up Windows XP Pro in a Virtual Machine and I also use Remote Desktop quite a bit to connect to our PeopleSoft and Hyperion Windows Servers.

So to wrap up this post I started off telling you about Sysinternals and ended up with the Microsoft Resource Kit so I actually touched on two Microsoft sites that are useful.

One last note in the above example I used sample path of: <path>\reskit\….. If you actually created a directory structure like that you would need to make sure it was contained within your Windows Environment variable %PATH%. You can add it to %PATH% by using the Control Panel->System app or you can just put the executable(s) into a directory that already is in your %PATH% like C:\Windows\system32. I use that location for some of my executable(s) but I also created a Tools directory (C:\Tools) and I put the majority of my non-standard Windows or rather non-delivered Windows programs there and I’ve added C:\Tools to my %PATH%).

One last last note. Back to Sysinternals. There is complete zip file available for download that is available at:

http://technet.microsoft.com/en-us/sysinternals/bb545027.aspx

Categories: PeopleTools · Windows Operating Systems · Windows Server · Windows XP

1 response so far ↓

  • KLAKII // September 4, 2008 at 3:22 am | Reply

    Hi, did you tested that you could successfully use the services provided by pageant.exe with the procedure you describe?
    I installed it as service, I checked that it is running and that it has read the private key in memory, but when trying to connect to a server, I cannot login with through the pageant process. Any advise?

    I’ve been using this method for several years now on all of my windows servers. You need to make sure you put your public keys into the authorized_keys file on the unix server you are connecting to and then test that you can sign in without being prompted for a password using the putty profile you created for that server (host) you are establishing a connection to.

Leave a Comment