locked
Install Windows Service Using InstallUtil.exe

    Question

  • It's my first to write a service with Visual Studio 2005, at first i had an application written as Console Application, I did copy the code into a new Windows Service Project so my code like like the following:

    Imports System.IO
    I
    mports System.Security
    Imports System.Security.Permissions
    Imports system.Data.Odbc

    Public Class Service1

    Protected Overrides Sub OnStart(ByVal args() As String)
    Watch()
    End Sub

    Protected Overrides Sub OnStop()
    Some code Here
    End Sub

    <Security.Permissions.PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
    Private Shared Sub Watch()
    Some code Here
    End Sub

    ' Define the event handlers.
    Private Shared Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
    ' Specify what is done when a file is changed, created, or deleted.
    End Sub

    Private Shared Sub OnRenamed(ByVal source As Object, ByVal e As RenamedEventArgs)
    ' Specify what is done when a file is renamed.
    End Sub

    End Class

    After I tried to run the service in VS 2005 a message box warned me that I can't run the service before intalling it using InstallUtil.exe, I did so by running InstallUtil.exe from the CMD Prompt with service.exe file created by VS 2005 in bin folder, but I got an error saying: " public installers with the RunInstallerAttribute.Yes attribute could be found..." and I couldn't install the service.

    Any Sugestions...is it my code problem or .NET framework.

    Thursday, October 19, 2006 3:50 AM

Answers

  • Probably and easier way to go.

    In the Windows Service "Design" view, right click, and select add installer.

    Create a setup project and add the primary output from your service to the setup project.

    Right click on the setup project and select custom actions.

    Add the primary output from your service project to each - Install, Commit, Rollback, Uninstall.

    Now you can build the setup project. After builing the setup project Right click on it to install and uninstall your service, all from within the IDE.

    Lastly, sometimes while testing devs put a thread sleep in the Service OnStart to enable manual attachement to the process for debugging - Tools Attach top Process and select your service exe.

    Rgds,

    Martin.

     

    Thursday, October 19, 2006 4:51 AM
  • Not sure if you actually added the right or not. you have created an account for your service and are using that yes? If so restart to ensure policy application to machine - not sure of sequence or commands in XP Pro stand alone setup to force policy re-application.

    I was able to replicate your error with the user not setup with an acconut without the Log on as a Service Right.

    If still having trouble set the Service Process Installer in your VS Project to use Account LocalSystem - properties dialogue in design view.

    Hopefully this will get you installed and of and running. you can change the account as used by the service using services.msc after install.

    rgds,

    Martin.

    Tuesday, October 24, 2006 4:50 AM
  • Hi Graham,

     

    I have just finished a small tutorial on creating an empty windows service in VB.NET. The address is:

     

    http://www.alanphipps.com/VisualBasicdotNET-WindowsService.html

     

    The source code is there too if you dont want to go through the tutorial.

     

    thanks

     

    Friday, April 06, 2007 12:08 PM

All replies

  • Probably and easier way to go.

    In the Windows Service "Design" view, right click, and select add installer.

    Create a setup project and add the primary output from your service to the setup project.

    Right click on the setup project and select custom actions.

    Add the primary output from your service project to each - Install, Commit, Rollback, Uninstall.

    Now you can build the setup project. After builing the setup project Right click on it to install and uninstall your service, all from within the IDE.

    Lastly, sometimes while testing devs put a thread sleep in the Service OnStart to enable manual attachement to the process for debugging - Tools Attach top Process and select your service exe.

    Rgds,

    Martin.

     

    Thursday, October 19, 2006 4:51 AM
  • Martin,

    Thanks for your help, it was really helpful, but when I am installing the Service a box pops up asking me to Set Service Password, After i do so I get an message saying "No mapping between account names and security IDs was done." after that I get another message saying: "Could not find file 'C:\Program Files\OU\Setup2\WatcherService.InstallState' " and the service won't install.

    any idea why.

    Thanks

    Friday, October 20, 2006 12:40 AM
  • Thanks for the help Martin;

      I am, however, stuck at the same point with the OP.

      I don't know if this is because I'm using a foreign language operating system or what, but regardless of the username I enter, it gives me the same errors OP is getting.  Are there any critical steps that I'm missing?

     

    Regards,

    Andy Huang

    Friday, October 20, 2006 9:47 AM
  • Hi Andy,

    Sorry about the delay.

     

    That error is from lack of account rights.

     

    If your service account is in a domain –

     

    Provide the “Log on as a Service” User Right through Group Policy.

     

    Using Active Director Users and Computers right click your Domain, select properties/ Group Policy.

     

    Double Click Default Domain Policy

     

    Select Computer Configuration/ Windows Settings/ Security Settings/ User Rights Assignment

     

    In the right window select “Log on as a service” and configure with your service account.

     

    If not in a domain please advise OS etc.

     

    Rgds,

    Martin - MCSE.

     

     

     

    Monday, October 23, 2006 7:25 AM
  • Hi Martin;

      No problem at all.  Any reply is better than no reply at all :)

      I've checked my gpedit.msc, and the user I am using does have logon as service rights.  I am, however, not on a domain.  This station (and the stations I intend to deploy this service on) is an individual station on a network w/o domain controller / active directory.

    All machines are Windows XP Pro SP2 (this one is localized in Japanese, rest of them are standard English USA).  The users logged on as all have local administrative access; in fact, this one is using the default "Administrator" account.  Please let me know if you need any more information in regards to the system configurations as I'm not sure what information you need.

    Many thanks,

    Andy Huang

    Monday, October 23, 2006 7:29 PM
  • Not sure if you actually added the right or not. you have created an account for your service and are using that yes? If so restart to ensure policy application to machine - not sure of sequence or commands in XP Pro stand alone setup to force policy re-application.

    I was able to replicate your error with the user not setup with an acconut without the Log on as a Service Right.

    If still having trouble set the Service Process Installer in your VS Project to use Account LocalSystem - properties dialogue in design view.

    Hopefully this will get you installed and of and running. you can change the account as used by the service using services.msc after install.

    rgds,

    Martin.

    Tuesday, October 24, 2006 4:50 AM
  • Hi,

     

    I am also writing my first service application with VS2005 and am having the same problem installing - "Could not find file .....appname.InstallState". I am using the localsystem account. Any ideas would be very welcome.

     

    Thanks

    Graham

    Tuesday, April 03, 2007 1:21 PM
  • Hi Graham,

     

    I have just finished a small tutorial on creating an empty windows service in VB.NET. The address is:

     

    http://www.alanphipps.com/VisualBasicdotNET-WindowsService.html

     

    The source code is there too if you dont want to go through the tutorial.

     

    thanks

     

    Friday, April 06, 2007 12:08 PM