为窗口服务创建安装项目

发布于 2024-07-19 03:26:21 字数 59 浏览 10 评论 0原文

为 Windows 服务创建部署项目需要哪些必要的项目? 在安装新版本之前,我需要卸载以前版本的服务。

What are the necessary items need from creating a deployment project for a windows service? I need to uninstall the previous version of the service before I install the new version.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

呆° 2024-07-26 03:26:21

MSDN 有一个关于创建 Windows 服务的教程和安装程序。

MSDN has a tutorial on creating a Windows Service and installer.

山色无中 2024-07-26 03:26:21

我在我的应用程序中使用 NSIS,安装服务时只需使用 sc 命令:

ExecWait 'sc create MyService binpath= "$INSTDIR\MyService.exe"'
ExecWait 'sc start MyService'

对于卸载:

ExecWait 'sc stop MyService'
ExecWait 'sc delete MyService'

效果很好。

I use NSIS for my apps, and for installing a service you just use the sc command:

ExecWait 'sc create MyService binpath= "$INSTDIR\MyService.exe"'
ExecWait 'sc start MyService'

And for uninstall:

ExecWait 'sc stop MyService'
ExecWait 'sc delete MyService'

Works great.

他是夢罘是命 2024-07-26 03:26:21

这几乎只是调用:

net stop "MyService"
intallutil.exe /u MyService.exe

// Copy your exe into place
installutil.exe MyNewService.exe

// optional
net start "MyService"

这会停止旧服务,卸载它,然后将新服务复制到位,安装它,然后(可选)启动它。

大多数安装程序都使这变得非常容易。 唯一的另一个“问题”是确保您的安装程序仅限于安装到本地驱动器,而不是网络路径,如果该服务要安装为在启动时自动运行。

It's pretty much just call:

net stop "MyService"
intallutil.exe /u MyService.exe

// Copy your exe into place
installutil.exe MyNewService.exe

// optional
net start "MyService"

This stops the old service, uninstalls it, then copies the new into place, installs it, and (optionally) starts it.

Most installers make this quite easy. The only other "gotcha" is to make sure your installer is restricted to install onto a local drive, not a network path, if the service is going to be installed to run automatically at startup.

聊慰 2024-07-26 03:26:21
  1. 在 Visual Studio 中,转到服务项目中的服务文件(myservice.vb 或 myservice.cs)。

  2. 右键单击设计视图,然后选择属性。

  3. “属性”窗口的底部有一个“添加安装程序”链接。 单击它。

  4. 查看 ServiceInstaller 和 ServiceProcessInstaller 属性。

  5. 编译您的项目

  6. 卸载以前的版本,在命令提示符下运行:Installutil.exe /uc:\myfolder\myservicefile.exe

  7. 进行安装,在命令提示符中,运行:Installutil.exe c:\myfolder\myservicefile.exe

就是这样。

Installutil.exe 位于 Windows 目录中的框架文件夹中。 它不必包含在您的项目中。

  1. In Visual Studio go to your Service file (myservice.vb or myservice.cs) in your service Project.

  2. Right click the design view, and choose properties.

  3. At the bottom of the Porperties window theres an Add Installer link. Click it.

  4. Check out the ServiceInstaller and ServiceProcessInstaller properties.

  5. Compile your project

  6. to uninstall the previous version, in the command prompt, run: Installutil.exe /u c:\myfolder\myservicefile.exe

  7. to install, in the command prompt, run: Installutil.exe c:\myfolder\myservicefile.exe

thats it.

Installutil.exe lives in the framework folder, somewhere in your Windows directory. It doesn't have to be included with your project.

冷月断魂刀 2024-07-26 03:26:21

如果您已经创建了安装程序,则安装项目不需要做太多额外的工作。 它可以让您直接从 Visual Studio 中安装和卸载。 网络上有很好的教程。

您将遇到的 2 个与服务相关的问题以及如何解决这些问题:

  • 您卸载了某个服务,但无法重新安装,因为您收到错误消息,表明该服务正在等待删除,并且需要重新启动必需的。
    => 关闭 Windows 服务管理器。 它将释放所有引用,您可以重新安装服务。

  • 您在卸载服务可执行文件之前删除了它,现在您无法“卸载”它来清理注册表。
    => 除了完全避免这种情况之外,我没有其他解决方案。

If you already created an installer, there is not much additional work to be done for a Setup project. It will let you install and uninstall directly out of Visual Studio. There are good tutorials on the web.

2 service-related issues that you will run into, and how to address them:

  • You uninstalled a service, but you can't reinstall is, because you get the error message that the service is pending deletion and that a reboot is required.
    => Close the Windows Service Manager. It will release any references, and you can reinstall your service.

  • You deleted a service executable before you uninstalled it, and now you can't 'uninstall' it to clean up the registry.
    => I have no solution for that one, other than avoiding this entirely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文