1

I have a custom windows service written in c# that I need to install and debug. When I use

installutil "[path].exe"

from the command line and then try and search for the service, it doesn't appear in the list of installed services anywhere. Looking at the install log file, i see this:

Installing assembly 'myservice'.   
Affected parameters are:  
   logtoconsole =    
   assemblypath = mypath  
   logfile = mylogfile  
Installing service MyService  
Service MyService has been successfully installed.  
Creating EventLog source MyService in log Application...  
Committing assembly 'myservice'.  
Affected parameters are:  
   logtoconsole =   
   assemblypath = myservice  
   logfile = pathtoinstalllog  
Uninstalling assembly myservice  
Affected parameters are:  
   logtoconsole =   
   assemblypath = myservice   
   logfile = pathtoinstalllog  
Removing EventLog source myservice.  
Service myservice is being removed from the system...  
Service myservice was successfully removed from the system.  
Uninstalling assembly myservice'.  
Affected parameters are:    
   logtoconsole =   
   assemblypath = myservice  
   logfile = pathtoinstalllog  
Removing EventLog source myservice.  
Service myservice is being removed from the system...  
Service myservice was successfully removed from the system.

(The names path, myservice, pathtoinstalllog, etc are in place of company specifics)

Anyway, from the log file it looks as if the service is being installed and then immediately uninstalled...

If any more code or info is needed, let me know, and thanks in advance.

Phillip Schmidt
  • 8,805
  • 3
  • 43
  • 67
  • Should't you be specifying the flag `-i` to tell it to `install`? – Suhas May 02 '12 at 17:19
  • are you getting any error in the log file??? Is that the complete log from installlog file. Also check if ur code is not causing uninstall – Sandeep Singh Rawat May 02 '12 at 17:25
  • oh, i thought that was the default value.. either way, it didn't change anything :\ – Phillip Schmidt May 02 '12 at 17:26
  • nope, no errors it would seem. That's the whole log file. Maybe I'm trying to install the wrong .exe? It's a windows service written in VS, so should i point the install to the .exe inside bin/release? or obj/release? – Phillip Schmidt May 02 '12 at 17:30
  • 1
    full path to your service main output (bin/debug/assembly.exe). Usually if there's an error it 'performs rollback' - it looks like it's doing so but your log doesn't say - so I'm guessing your 'myservice' is wrong path or something. What do you have in C# installer class? User you're using to log in etc... – NSGaga-mostly-inactive May 02 '12 at 17:31
  • I think you're right. I tried using obj/debug/filename instead of bin to get around an admin rights issue and thats when I got that error. When I try bin/debug/filename i get a rollback with an access denied error. Ill have to sort out the admin thing on my own, but I'll post back with whether or not that fixed it – Phillip Schmidt May 02 '12 at 17:39
  • before I do that, though, could using the .exe in obj/debug instead of bin/debug even cause this? – Phillip Schmidt May 02 '12 at 17:41
  • 1
    shouldn't, but depends on how you build/set up things. Anyway, for accounts issues - 'run as admin' (the command prompt etc.) and for service to use (till you sort out) - let it 'pop' up and use some admin account name - UNC path '.\User' or something. Many things could go wrong with InstallUtil (it's the safest method I found, but once you know how to use it), use right 32/64 version (and right InstallUtil .NET version path) etc. and watch for errors. – NSGaga-mostly-inactive May 02 '12 at 17:48
  • Well, I can't run as admin because my company uses ViewFinity to elevate privileges to necessary programs (and obviously for security reasons cmd prompt isn't included). But thats an easy problem to solve. – Phillip Schmidt May 02 '12 at 17:52
  • I think you'd have to 'run as admin' / elevate for service to set up. Let me know if this helps for me to post an answer. – NSGaga-mostly-inactive May 02 '12 at 17:58
  • Go ahead and post it. Whether it is the only problem or not, you solved the issue that this question addresses. If it turns out that there is another issue, I'll make a separate question for it. – Phillip Schmidt May 02 '12 at 18:04
  • np :), glad to help - I just posted an 'official' answer, I think that sums it up, best. – NSGaga-mostly-inactive May 02 '12 at 19:02

1 Answers1

2

to sum it up per our discussion...

  • use 'InstallUtil full-path' to your service main output (bin/debug/assembly.exe). Usually if there's an error InstallUtil 'performs rollback' (so watch for errors) - it looks like it's doing so but your log doesn't say - so I'm guessing your 'myservice' is of wrong path (also pick the right InstallUtil version, .NET framework and 32/64)...

  • for security/account issues - run InstallUtil elevated ('run as admin', the command prompt etc.) - (and for additional debugging if needed, try specifying different user/type for your service account, check your installer class details, RunInstaller attribute etc.).

hope this helps

NSGaga-mostly-inactive
  • 14,052
  • 3
  • 41
  • 51
  • last question- i'm using the SYSTEM user for the service. Is this ok, and if not, how do I change it? EDIT: Nevermind, i found it in the installer code. first question still stands though lol – Phillip Schmidt May 02 '12 at 19:30
  • yes, in the installer - `I wouldn't use the 'system' account` (I'm guessing you're talking about the LocalSystem). `The preference is always to go with the 'least privileged' one, usually the 'ServiceAccount.LocalService' if it gets the job done`. Go through the 'System.ServiceProcess.ServiceAccount' descriptions, it says a bit about each of them. Ideally, for proper security setup (and to be able to micro-manage, control later) `if you can, set up a separate user (for the service or a 'category' of similar services) and give it 'just enough' privileges`. But that's more of a 'security' q:) – NSGaga-mostly-inactive May 02 '12 at 19:55
  • http://stackoverflow.com/questions/510170/the-difference-between-the-local-system-account-and-the-network-service-acco - or this link – NSGaga-mostly-inactive May 02 '12 at 19:56