How to Make a Custom Service on Windows

The next step is to make a custom start-up service for Windows. That is , if we reboot it remotely, the connection will also be established automatically.

First, for a startup service, the reference page is: Set up an SSH tunnel as a Windows service using putty (plink).

1. Download the kit and install it.

2. Use the command to insert a new service with srvany:

cmd > insrsrv {service name} {location of srvany program}

3. Install the service’s detail for register. Coping the following entries to a .reg file, modifying the corresponding commands, and then double-click it to install. Note: the reverse-slash (‘\’) must write twice for escape.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{service name}\Parameters]
“Application”=”{location of plink}\\plink.exe”
“AppDirectory”=”{location of directory of plink}
“AppParameters”=”{ssh arguments}

4. After install it. You can use this command for testing.

cmd > net [start/stop] {service name}

5. When start up the service, check at the server side by netstat.

Second, for the detail when plink could not detect the host ssh key, the reference here: Add host keys for putty (plink) for the system user.

In default the connection is established by the owner. But a service is ran by the system who cannot retrieve the host key we presently used. To overcome this problem, the steps listing:

1. Connect server by hand to get the host key in local pc (as a double check).

2. Open regedit and find out the key: HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys.

3. Export these entries from menu and modify the exported file’s entry header to:

[HKEY_USERS\.DEFAULT\Software\SimonTatham\PuTTY\SshHostKeys]

4. Save and install it by double click. Then check the service for correctness.

Till now, the auto-login ssh tunnel service on Windows constructed. Then the next step is to check its connection and may it keep alive.

Leave a Reply

Your email address will not be published. Required fields are marked *