【问题标题】:window service installation issues窗口服务安装问题
【发布时间】:2013-08-21 16:04:28
【问题描述】:

我在使用 c# 安装窗口服务时遇到问题。当我创建我的第一个窗口服务项目时,我遇到了以下问题: “无法从命令行或调试器启动服务。必须先安装 Windows 服务(使用 installutil.exe),然后使用 ServerExplorer、Windows 服务管理工具或 NET START 命令启动”。

然后我将我的 program.cs 编辑为:

    static void Main()
{
    if (System.Diagnostics.Debugger.IsAttached)
    {
        Service1 service = new Service1();
        string[] args = new string[] { "arg1", "arg2" };
        service.StartFromDebugger(args);
    }
    else
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new Service1() 
        };
        ServiceBase.Run(ServicesToRun);
    }
}

// Also added the following code
public partial class Service1 : ServiceBase
{
    public void StartFromDebugger(string[] args)
    {
        OnStart(args);
    }

}

那么这个问题就解决了。之后,当我通过添加新的安装项目创建该项目的 .exe 文件并将其安装在我的系统上时,它再次给了我上述错误。 请帮助我....thanx提前

【问题讨论】:

  • 这不是直接的答案,但请尝试top-shelf。它使您可以更轻松地构建和调试 Windows 服务。

标签: .net service window


【解决方案1】:

安装服务的最简单方法如下:

转到 CMD 并以管理员身份运行它

写下这个命令::

sc create  YourServiceName displayname= "Service Name to be displayed" binpath= c:\YourService.exe start= demand

您的 exe 文件和 config.exe 的路径应该相同以避免数据库连接问题。 一旦你运行它,它会给你一个成功的消息......

【讨论】:

    【解决方案2】:

    您需要通过单击服务设计器窗格上的添加安装程序来添加服务安装程序。 youtube 上有一个关于使用 C# 创建和安装 Windows 服务的精彩视频。

    【讨论】:

      【解决方案3】:

      安装 Windows 服务的最简单方法。在发布模式下构建您的 Windows 服务,然后复制 bin 发布中的所有文件,然后放入文件夹中

      以管理员身份打开命令提示符进入该文件夹,然后使用此命令

      installutil yourservicename.exe(在relese里面有一个文件)

      卸载///

      installutil /u yourservicename.exe (在版本中有一个文件) 或者 installutil -u yourservicename.exe (relese里面有个文件)

      干杯

      【讨论】:

        【解决方案4】:

        Windows 服务: 第 1 步:

              First step is to add installer
        

        第 2 步:

          点击您的服务并给出显示名称

        第 3 步:

             Select Local system  
        

        第 4 步:

             Open Developer command prompt
        

        第 5 步:

            InstallUtil your_service_path/Your_service_display_name.exe
        

        第 6 步:

              net start Your_service_display_name
        

        这是链接

                   https://youtu.be/rG3Ts5CrTUA
        

        【讨论】:

          猜你喜欢
          • 2013-10-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-16
          • 2013-12-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多