简体   繁体   中英

C# cannot create windows service that will start

I'm trying to write my first Windows Service in C#. If I follow the MS tutorial to the letter, I can create a simple service with a timer that works and writes to the eventLog. The second I change ANYTHING it will not start with 1064. I installed the service by calling C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe from the solution's bin\debug folder. I have uninstalled the service and reinstalled it. I have used SC DELETE and reinstalled it. I have rebooted. Nothing works, unless I start a new project from scratch, which fails again when I try to change anything. Does something have to be reset if you change code?

Starting again with baby steps and careful use of the event log I was able to determine that the service could not access a file path which referred to a drive created with a SUBST command (I don't have an E drive on the development machine). I presume this is because the SUBST is not in the service's process, however why that caused the service controller to error on startup I don't know, possibly because the path was accessed from Properties.Settings.Default. The mystery fact remains that a working version stopped working when I only changed the service display name and rebuilt (after uninstalling & reinstalling).

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