Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > User option to select "Log on" when installing VB .NET Windows Service
 

User option to select "Log on" when installing VB .NET Windows Service

Hi,

I am trying to install a VB .NET Service. Before InitializeComponent() method in Sub New() of the ProjectInstaller class, I am creating an object of a Windows form to get the user input (UserName, Password, and some other text boxes for the setup which service will use later). I was able to successfully install and start the service if I set either Account = User or Account = LocalSystem in the Properties window of ServiceProcessInstaller.

Now, I want to let user select and based on the input I want to change the Account Type. For this, I have radio buttons to select either of the two options and in Sub New() method, I have the following code, which isn't working -

Public Sub New()

MyBase New()

   NewForm.ShowDialog()

   If NewForm.RadioButton1.Checked Then

      Me.ServiceProcessInstaller1.Account = ServiceAccount.User
      UserNameString = "ABC"
      PasswordString = "ABC"
  
   ElseIf NewForm.RadioButton2.Checked Then

      Me.ServiceProcessInstaller1.Account = ServiceAccount.LocalSystem
    
   End if

End Sub



I think its because the installstate and other service installation files are already copied to the installation folder before NewForm pop-ups and it has Account type already set to either User or LocalSystem.

Can anyone suggest me a way to perform the tweak and make it running?

Thanks!

Regards.
Vishal Sheth
Vishal_MSDN  Friday, September 25, 2009 7:19 PM
The service isn't installed at the time the files are copied to disk. It's the Install method of the Service Installer class that makes that exe a service. So what's important is whether you call this dialog in the Install method at the right time. I can't tell from that code fragment.
Phil Wilson
PhilWilson  Friday, September 25, 2009 8:39 PM
Thanks PhilWilson for the reply.

Actually I figured out a work around for this, sorry for posting it late. It might help others looking for similar solution. In ProjectInstaller.vb file -

Public Class ProjectInstaller

Public AccountType As New System.ServiceProcess.ServiceAccount

Public Sub New()

MyBase New()

   NewForm.ShowDialog()

   If NewForm.RadioButton1.Checked Then

      AccountType = ServiceAccount.User
      UserNameString = "ABC"
      PasswordString = "ABC"
  
   ElseIf NewForm.RadioButton2.Checked Then

      AccountType = ServiceAccount.LocalSystem
    
   End if

End Sub
End Class

In ProjectInstaller.Designer.vb -

Private Sub InitializeComponent()<br/>
        <br/>
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ProjectInstaller))<br/>
        Me.ServiceProcessInstaller1 = New System.ServiceProcess.ServiceProcessInstaller<br/>
        Me.ServiceInstaller1 = New System.ServiceProcess.ServiceInstaller<br/>
        '<br/>
        'ServiceProcessInstaller1<br/>
        '<br/>
       <strong> Me.ServiceProcessInstaller1.Account = AccountType</strong>
<br/>
        Me.ServiceProcessInstaller1.Password = PasswordString<br/>
        Me.ServiceProcessInstaller1.Username = UserNameString<br/>
        <br/>
        Me.Installers.AddRange(New System.Configuration.Install.Installer() {Me.ServiceProcessInstaller1, Me.ServiceInstaller1})<br/>
<br/>
End Sub


By this, you can avoid Set Service Login pop-up window and customize the login credentials from your own form. Thanks!

Best Regards!

Vishal Sheth
Vishal_MSDN  Tuesday, September 29, 2009 5:29 PM
The service isn't installed at the time the files are copied to disk. It's the Install method of the Service Installer class that makes that exe a service. So what's important is whether you call this dialog in the Install method at the right time. I can't tell from that code fragment.
Phil Wilson
PhilWilson  Friday, September 25, 2009 8:39 PM
Thanks PhilWilson for the reply.

Actually I figured out a work around for this, sorry for posting it late. It might help others looking for similar solution. In ProjectInstaller.vb file -

Public Class ProjectInstaller

Public AccountType As New System.ServiceProcess.ServiceAccount

Public Sub New()

MyBase New()

   NewForm.ShowDialog()

   If NewForm.RadioButton1.Checked Then

      AccountType = ServiceAccount.User
      UserNameString = "ABC"
      PasswordString = "ABC"
  
   ElseIf NewForm.RadioButton2.Checked Then

      AccountType = ServiceAccount.LocalSystem
    
   End if

End Sub
End Class

In ProjectInstaller.Designer.vb -

Private Sub InitializeComponent()<br/>
        <br/>
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ProjectInstaller))<br/>
        Me.ServiceProcessInstaller1 = New System.ServiceProcess.ServiceProcessInstaller<br/>
        Me.ServiceInstaller1 = New System.ServiceProcess.ServiceInstaller<br/>
        '<br/>
        'ServiceProcessInstaller1<br/>
        '<br/>
       <strong> Me.ServiceProcessInstaller1.Account = AccountType</strong>
<br/>
        Me.ServiceProcessInstaller1.Password = PasswordString<br/>
        Me.ServiceProcessInstaller1.Username = UserNameString<br/>
        <br/>
        Me.Installers.AddRange(New System.Configuration.Install.Installer() {Me.ServiceProcessInstaller1, Me.ServiceInstaller1})<br/>
<br/>
End Sub


By this, you can avoid Set Service Login pop-up window and customize the login credentials from your own form. Thanks!

Best Regards!

Vishal Sheth
Vishal_MSDN  Tuesday, September 29, 2009 5:29 PM

You can use google to search for other answers

Custom Search

More Threads

• Source path of installation
• Multiple signing and publishing bug
• How can temp files be removed before the setup program is committing in VS.net 2005 SetUp project
• VB.Net App Compilation
• how to create a setup without 2.0 framework installation?
• Problem with the install
• dfsvc crash
• Creating Windows App. Installer
• Store Destination Path of File in Registry-Key
• Content file - size limitation