无法在Windows XP Embedded上启动用.NET 2.0编写的服务

时间:2010-03-09 22:28:54

标签: c# .net windows-services .net-2.0

我创建了一个小型可执行文件,可以通过调用MyApp.exe作为普通应用程序启动,也可以通过调用MyApp.exe -s作为服务启动。因为我试图保持尽可能简单,我通过手动运行

“安装”此应用程序
sc create MyAppService binPath= "C:\MyApp\MyApp.exe -s"

然后我像net start MyAppService一样正常启动服务。

在两台Windows XP计算机和两台Windows 2000计算机上,这样可以正常工作。但是,在两台不同的Windows XP Embedded机器上,当我尝试启动该服务时,我收到消息:

  

发生了系统错误1083.

     

此服务配置为运行的可执行程序未实现该服务。

在一台机器上,我能够通过卸载并重新安装.NET 2.0来解决这个问题,但是在第二台机器上,这不起作用。

我不确定如何调试此功能,只搜索谷歌似乎只会出现因BET和Exchange服务而失败的特定服务。

下面是类MyApp,它是启动类,MyAppService,它是扩展ServiceBase的类。提前感谢您的任何指示。

MyApp.cs

static class MyApp
{
    [STAThread] static void Main( string[] args )
    {
        ....
        switch ( arg1 )
        {
            case "-s":
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { new MyAppService() };
                ServiceBase.Run( ServicesToRun );
                break;
             ....
        }
    }
}

MyAppService.cs:

class MyAppService : ServiceBase
{
    static MyAppService()
    {
        // ...
    }

    protected override void OnStart( string[] args )
    {
        // ...
    }
}

3 个答案:

答案 0 :(得分:1)

在桌面上,如果服务未在Windows注册表中正确注册svchost实例应在其下运行的帐户下,则会发生这种情况。我没有XPe的经验,但尝试查看HKLM \ Software \ Microsoft \ Windows NT \ CurrentVersion \ Svchost并确保为该帐户正确列出了MyAppService。

答案 1 :(得分:0)

  1. 如果有包含安全日志的有用信息,请尝试检查事件日志。
  2. 似乎无法将MyAppService识别为服务,或者MyApp.exe不会向XPe公开任何服务。专注于此事以找到根本原因。
  3. 对于快速测试,您可以使用VMWare在开发PC中运行XPe。 VMWare可以将当前运行的XPe复制到映像中并复制到您的PC,但不确定它是否可以正常工作。

答案 2 :(得分:0)

看来我有同样的问题。 ServiceController.Start()无法成功启动服务。该应用程序位于C#.NET2中并在Window XPe中运行。解决方法如下:

TimeSpan timeout = TimeSpan.FromMilliseconds(20000);
while (true)
{
    ServiceController service = new ServiceController("myservice");
    service.MachineName = ".";
    try 
    {
       service.Start()
       service.WaitForStatus(ServiceControllerStatus.Running, timeout);
    }
    catch
    {  
        service.Stop();
        continue;
    }
 }

循环2或3次后,服务通常会成功启动。 但是30-40秒已经过去了。这是不可接受的 有没有人在这个问题上经历过?谢谢!

相关问题