【发布时间】:2012-12-24 14:21:04
【问题描述】:
好的,这是我的 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。
【问题讨论】:
-
为了测试,请尝试将文件写入c:\test.txt,或任何其他非系统无保护目录。
-
好吧,我确实试过写 F:\test.txt 得到了同样的错误
标签: c# .net windows-services event-viewer