从命令行安装服务 (VB Express 2008) [英] Install a service from command line (VB Express 2008)

查看:33
本文介绍了从命令行安装服务 (VB Express 2008)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注 http://michaelellerbeck.com/2009/01/12/creating-a-service-for-visual-basic-2008-express/ 用于使用 VB Express 2008 创建服务.我得到了第一部分工作并设法使用 InstallUtil 安装示例,但第二部分让您使用带有按钮的表单来安装和卸载服务.

I've been following a tutorial on http://michaelellerbeck.com/2009/01/12/creating-a-service-for-visual-basic-2008-express/ for creating a service using VB Express 2008. I got the first part working and managed to get the sample to install using InstallUtil, but the second part has you use a form with buttons to install and uninstall the service.

我想知道是否有从命令行安装服务的说明,这样我就可以切换到特定的子目录并输入myservice/i"来安装它或输入/u 来卸载它.

I'm wondering if there are instructions for installing the service from a command line so I could just change to a specific subdirectory and type "myservice /i" to install it or /u to uninstall it.

有什么建议或教程可以做到这一点吗?

Any advice or tutorials to do this?

推荐答案

在您提供的示例中,使用未记录的调用安装服务的代码:

In the example you have provided, the code that installs the service using the undocumented call:

Try
    System.Configuration.Install.ManagedInstallerClass.InstallHelper(New String() {"C:\Test\YourService1.exe"})
Catch ex As Exception
    MessageBox.Show(ex.ToString)
End Try

放置在按钮下的事件处理程序中.好吧,没有什么可以阻止您直接执行此代码.

is placed in an event handler under a button. Well, there's nothing preventing you from executing this code directly.

为此,只需创建一个控制台应用程序,然后将上面的代码粘贴到入口点 Sub Main() 中.然后,创建您的可执行文件.

To do that, just create a console application, and paste the code above into the entry point, Sub Main(). Then, create your executable.

这篇关于从命令行安装服务 (VB Express 2008)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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