如何在安装程序中添加Windows服务 [英] how to add windows service in a installer

查看:173
本文介绍了如何在安装程序中添加Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友



i有一个Windows服务exe文件,我已经包含在visual studio项目中

但它正在处理该文件作为普通文件而不是将其注册为windows

服务我该怎么做呢。请建议

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

推荐答案

使用开发人员命令提示符

您可以安装服务在Visual Studio Developer命令提示符中使用以下命令

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



您可以找到Visual工作室开发人员命令提示符

开始 - Visual Studo XXXX - Visual Studio工具 - VSXXXX的开发人员命令提示



确保已使用以管理员身份运行打开此选项(右键单击 - 以管理员身份运行)



使用Windows命令提示符


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



注意:您机器上的v4.0.30319可能有所不同



使用安装项目

但是如果你想通过安装项目安装服务那么慢慢地这些步骤 -

1.打开你的服务文件(例如Service1.cs)在设计模式中,右键单击并单击添加安装程序。请注意,现在可以看到2个控件,其名称如 serviceProcessInstaller1 ServiceInstaller1

2.在属性窗格中,更改帐户属性 LocalSystem

3.右键单击 ServiceInstaller1 并将 StartType 属性更改为自动

4.根据您的要求进行更改(如果有)(如服务名称等)

5.添加安装项目到您的解决方案

6.在解决方案资源管理器中,右键单击您的安装项目,选择添加,然后单击项目输出

7.在添加项目输出组对话框的项目框中,单击YourServiceName。单击主要输出,然后单击确定

8.构建整个解决方案。



您的设置应该准备就绪。



更新:




使用批处理文件

1.打开记事本

2。粘贴以下代码并更改服务名称(如果需要,还可以更改框架版本)


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 。从文件单击 SaveAs 。使用名称和扩展名保存 .bat

4.从放置服务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 :)


这篇关于如何在安装程序中添加Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆