New Windows Service installed, fails to start: “System error 2 … system cannot find the file specified”

后端 未结 6 1781
广开言路
广开言路 2021-02-04 23:43

I have installed several other custom .Net windows services successfully. A new one I had recently written was very similar to the others and while it installed without error -

6条回答
  •  天涯浪人
    2021-02-05 00:05

    I experimented with some test services and found it was not the length of any property that caused my problem (“System error 2 ... system cannot find the file specified”) to begin with. My built in service installer uses three properties: ServiceName, ServiceTitle, ServiceDescription. On installing, I found that it writes full service path to the registry, but it doesn’t just take the actual exe (assembly) name, it uses the ServiceName property to build the path! My issue was that the ServiceName and assembly name didn’t match, hence file not found. I used a powershell registry query to expose the path and finally noticed the mismatch from there. When I first noticed the problem I had not noticed that when I shortened the service name from whatever it was – that I just used the assembly name without the .exe and that is what actually fixed it, not simply shortening it.

提交回复
热议问题