Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends

i have a windows service exe file which i have included in the visual studio project
but it is treating that file as a ordinary file and not registering it as a windows
service how can i do that. please advice
Posted
Comments
[no name] 6-Aug-15 9:32am    
This, https://msdn.microsoft.com/en-us/library/zt39148a(v=vs.100).aspx might help you.

1 solution

Using Developer Command Prompt
You can install a service using following command in Visual Studio Developer Command Prompt
installutil.exe YourService.exe

You can find Visual Studio Developer Command Prompt in
Start -- Visual Studo XXXX -- Visual Studio Tools -- Developer Command Prompt for VSXXXX

Make sure that you have opened this with "Run as administrator" (Right click -- Run as administrator)

Using Windows Command Prompt
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" YourService.exe

Note: v4.0.30319 can be different on your machine

Using Setup Project
But if you want to install the service through setup project then follow these steps-
1. Open your service file (ex. Service1.cs) in Design Mode, right click and click Add Installer. Note that 2 controls will be visible now with name like serviceProcessInstaller1 and ServiceInstaller1
2. n the Properties pane, change the Account property to LocalSystem
3. Right click on ServiceInstaller1 and change StartType property to Automatic
4. Do the changes as per you requirement, if any (like service name etc.)
5. Add a Setup Project to your solution
6. In Solution Explorer, right-click on your setup project, select Add and then click Project Output
7. In the Add Project Output Group dialog box, in the Project box, click YourServiceName. Click Primary Output, and then click OK.
8. Build the whole solution.

Your setup should be ready.

UPDATE:


Using Batch File
1. Open Notepad
2. Paste following code and change the service name (& framework version if required)
@ECHO OFF

REM The following directory is for .NET 4.0 & you may change according to framework version installed in your system
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil" "YourService.exe"

3. From File click SaveAs. Save it with a name and with extension .bat
4. Execute this batch file from the same location where your service exe is placed.

Hope, it helps :)
 
Share this answer
 
v2
Comments
srilekhamenon 7-Aug-15 1:07am    
Thank you for your solution. Actually my problem is i have a windows service exe file
i can not use the code because i have made some changes in the code and i want to release the old service. so iam trying to add the old service in the installer program
Suvendu Shekhar Giri 7-Aug-15 1:26am    
Check the updated solution.
srilekhamenon 7-Aug-15 2:01am    
yes this can be solution i will try to execute batch file in custom action of the installer. Let Me try :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900