Having few problems with Windows Service

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
 
T

trant

Ok I solved problem #2...

It turns out I made a stupid error.

I actually set the service type to be "LocalService" instead of
"LocalSystem" !
 
J

JY

Have you added the service project output to the custom actions in the
installer project? If so it should work fine. I develop many services and
have never had a problem.
 
T

trant

Yeah, I have done that, at least I am pretty sure I did it right.

in Visual Studio IDE:
-I click my Setup project to select it
-I click Custom Actions icon which is at the top of the menu bar for
Solution Explorer
- On the screen I get a tree with 4 nodes: Install, Commit, Rollback and
Uninstall. I Right click Install and choose Add Custom Action.
- Under there I dbl-click Application Folder and then choose Primary output
from my service project (it is the only option available)

That should be it, right?

Do I need to do the same thing for the Uninstall section? The tutorial
didn't mention needing to do that there
 
T

trant

OK here check this out, I created another Windows Service project the same
way but I added virtually no custom code, so it's basically just an empty
shell.

But it clearly demonstrates the problem I am experiencing:

I run my setup, it installs my service
Then I run uninstall but it does not even stop the service it installed let
alone remove it.

Here is my project for you to download and see what I did wrong:
http://members.verizon.net/~vze28272/ServiceTest.zip
 
J

JY

But again you haven't added the service to the Uninstall custom action node,
so it won't uninstall.
 
T

trant

Yeah- that's the problem!

See this tutorial I dont think it ever mentions doing that...

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top