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

发布于 2024-08-24 16:39:29 字数 1344 浏览 3 评论 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 来修复此问题,但在第二台机器上这不起作用。

我不知道如何调试这个问题,搜索 google 似乎只能找到因此消息而失败的特定服务,例如 BITS 和 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 )
    {
        // ...
    }
}

I've created a small executable that can be launched either as a normal application by calling MyApp.exe or as a service by calling MyApp.exe -s. Because I'm trying to keep as simple as possible, I "install" this app by manually running

sc create MyAppService binPath= "C:\MyApp\MyApp.exe -s"

Then I start the service with net start MyAppService like normal.

On two Windows XP machines and two Windows 2000 machines, this works fine. However, on two different Windows XP Embedded machines, when I try to start the service I get the message:

System error 1083 has occurred.

The executable program that this service is configured to run in does not implement the service.

On one machine, I was able to fix this by uninstalling and reinstalling .NET 2.0, but on the second machine this did not work.

I'm not sure how to go about debugging this, and searching google only seems to turn up specific services that fail with this message such as BITS and an Exchange service.

Below are the classes MyApp, which is the startup class, and MyAppService, which is the class that extends ServiceBase. Thanks in advance for any direction on this.

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 )
    {
        // ...
    }
}

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

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

发布评论

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

评论(3

岛歌少女 2024-08-31 16:39:29

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

On the desktop, this can happen if the service isn't registered correctly in the Windows Registry under the account that the svchost instance is supposed to run under. I don't have experience in XPe, but try looking in HKLM\Software\Microsoft\Windows NT\CurrentVersion\Svchost and make sure that MyAppService is correctly listed for the account.

岁月染过的梦 2024-08-31 16:39:29
  1. 尝试检查事件日志中是否有包括安全日志在内的有用信息。
  2. 似乎没有将 MyAppService 识别为服务,或者 MyApp.exe 没有向 XPe 公开任何服务。专注于这件事以找到根本原因。
  3. 为了快速测试,您可以使用 VMWare 在开发 PC 中运行 XPe。 VMWare有办法将当前运行的XPe复制到镜像中并复制到您的PC上,但不确定它是否可以正常工作。
  1. Try to check in the Event log if there is useful info including Security log.
  2. It seems did not recognize the MyAppService as a service or MyApp.exe does not expose any services to the XPe. Focus on this thing to get the root cause.
  3. For fast testing, you can get XPe run in your development PC by using VMWare. VMWare has the way to copy the current running XPe into image and copy to your PC but not sure if it can work properly.
携君以终年 2024-08-31 16:39:29

看来我也有同样的问题。 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秒过去了。这是不可接受的。
有人在这个问题上有过经验吗?谢谢!

It appears that I have the same problem. The ServiceController.Start() does not start service successfully. The application is in C# .NET2 and running in Window XPe. The work around is below:

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;
    }
 }

after looping 2 or 3 times, the service usually get started successfully.
But 30-40 seconds has passed. This is not acceptable.
Dos anybody have experienced on this issue? Thanks!

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