Friday, July 12, 2013

Creating a custom Service

Well, basically if you are using a Windows server or you are doing a lot of development work, you might be running a lot of services locally. (Ex: Apache, WAMP, etc...) Imagine how much time you can save by creating a Service that will start these programs automatically.

Steps for creating a new Windows Service
Before moving on any further, you will need to grab hold of these 2 files first.
They are instsrv.exe and srvany.exe.

Click here to download the files now.
Click here to download the original package from Microsoft.
(If you are using the package from Microsoft,
you will need to extract the files from the package.)

Step 1 - Open up the Windows Start menu, enter cmd into the
Search programs and files field, Right-Click on the program
cmd.exe and select Run as Administrator.

Step 2 - Enter the following into the Command Prompt window.

"{yourPath}\instsrv.exe" {name} "{yourPath}\srvany.exe"
Replace {yourPath} with the directory that has the files instsrv.exe and srvany.exe.
Replace {name} with the Name of the new Service that you are going to create.

And there you go, you have successfully created a new Empty Service.

Step 3 - Open up the Windows Start menu, enter regedit into the
Search programs and files field and run the program regedit.exe.

Step 4 - Look for the new Service under the following directory.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{name}
Replace {name} with the Name of the new Service that you have created.

Step 5 - After selecting the new Service that you have created, Right-Click and
create a new Key. Rename the new Key as Parameters

Step 6 - Under Parameters add a few new String Value.

Step 7 - Entering some values
NameTypeData
ApplicationREG_SZ{the full path of your application}
Ex: G:\service\run_notepad.bat
AppDirectoryREG_SZ{the path to your application}
Ex: G:\service\

Step 8 - Open up the Windows Start menu, enter services into the
Search programs and files field and run the program Services.

Step 9 - Locate and open up the new Service that you have created.

Step 10 - You can set the Startup Type to either Automatic or
Automatic (Delayed start). (Automatic will start the Service
when Windows boots up. Automatic (Delayed start) will start 2 minutes
after the last Automatic Service has been executed.)

On top of that, some programs will only run smoothly with a particular user
account. That's where the Log On tab comes in. You can specify the
User Account Credentials that you are going to use when you run this Service.

Step Remove - To remove a Service,
type the following command in Command Prompt window.

"{yourPath}\instsrv.exe" {name} REMOVE
Replace {yourPath} with the directory that has the file instsrv.exe.
Replace {name} with the Name of the Service that you are going to delete.

And there you go, you have successfully removed a Service.

No comments:

Post a Comment