好的,这是我的OnStart
方法代码
File.CreateText("test.txt");
StreamWriter write = File.AppendText("test.txt");
write.WriteLine("Hello world, the service has started");
write.Flush();
write.Close();
我成功地安装了该服务。但是,当我启动时,我收到服务启动然后停止的消息。当我检查事件查看器时,它给了我这个
Service cannot be started. System.IO.IOException: The process cannot access the file 'C:\Windows\system32\test.txt' because it is being used by another process.
好的,这里发生了什么。我认为这不是权限问题,因为 ProcessInstaller 设置为 LocalSystem。