简体   繁体   中英

Unable to start service written in .NET 2.0 on Windows XP Embedded

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

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.

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!

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM