T
trant
I followed an online tutorial to create a Windows Service with a Setup and
I'm noticing two problems I can't figure out. The tutorial I used is located
here: http://www.grinn.net/blog/dev/2008/01/windows-services-in-c-part-1.html
Here are my problems:
1. The uninstaller does not remove my service. So after uninstalling and
trying to install again I get an error that the service already exists.
I have to go into the command line and type "sc delete MyService" to get rid
of my service manually.
Why doesn't the uninstaller handle this??
2. In my service I use File.AppendAllText to write to a file on the file
system. When I was running the code in my little test Console App it was
working fine but now when I run the same code within this service I get this
error:
Access to the path 'D:\myapp.log' is denied
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean
bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding)
at System.IO.File.AppendAllText(String path, String contents, Encoding
encoding)
at System.IO.File.AppendAllText(String path, String contents)
at MyService.MyServiceMain.Log(String msg)
I set this service up like the tutorial says to be LocalSystem
I'm noticing two problems I can't figure out. The tutorial I used is located
here: http://www.grinn.net/blog/dev/2008/01/windows-services-in-c-part-1.html
Here are my problems:
1. The uninstaller does not remove my service. So after uninstalling and
trying to install again I get an error that the service already exists.
I have to go into the command line and type "sc delete MyService" to get rid
of my service manually.
Why doesn't the uninstaller handle this??
2. In my service I use File.AppendAllText to write to a file on the file
system. When I was running the code in my little test Console App it was
working fine but now when I run the same code within this service I get this
error:
Access to the path 'D:\myapp.log' is denied
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean
bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding)
at System.IO.File.AppendAllText(String path, String contents, Encoding
encoding)
at System.IO.File.AppendAllText(String path, String contents)
at MyService.MyServiceMain.Log(String msg)
I set this service up like the tutorial says to be LocalSystem