Installing Windows Service
>>>> I can install a service as localsystem successfully as follows:
Dim context As New System.Configuration.Install.InstallContext("insta ll.log", Nothing)
context.Parameters.Add("assemblyPath", ServicePath)
Dim serviceProcessInstaller1 As New System.ServiceProcess.ServiceProcessInstaller
serviceProcessInstaller1.Account = ServiceProcess.ServiceAccount.LocalSystem
'serviceProcessInstaller1.Account = ServiceProcess.ServiceAccount.User
'serviceProcessInstaller1.Username = "User1"
'serviceProcessInstaller1.Password = "pw1"
Dim serviceInstaller1 As New System.ServiceProcess.ServiceInstaller
With serviceInstaller1
.StartType = ServiceStartMode.Automatic
.Context = context
.ServiceName = ServiceName
.DisplayName = ServiceName
.Parent = serviceProcessInstaller1
End With
serviceInstaller1.Install(New Hashtable)
>>>>> But when I try to use a user account instead I get this error:
An unhandled exception of type 'System.NullReferenceException' occurred in system.serviceprocess.dll
Additional information: Object reference not set to an instance of an object.
>>>>>> Here's the code I'm trying to run:
Dim context As New System.Configuration.Install.InstallContext("insta ll.log", Nothing)
context.Parameters.Add("assemblyPath", ServicePath)
Dim serviceProcessInstaller1 As New System.ServiceProcess.ServiceProcessInstaller
' serviceProcessInstaller1.Account = ServiceProcess.ServiceAccount.LocalSystem
serviceProcessInstaller1.Account = ServiceProcess.ServiceAccount.User
serviceProcessInstaller1.Username = "User1"
serviceProcessInstaller1.Password = "pw1"
Dim serviceInstaller1 As New System.ServiceProcess.ServiceInstaller
With serviceInstaller1
.StartType = ServiceStartMode.Automatic
.Context = context
.ServiceName = ServiceName
.DisplayName = ServiceName
.Parent = serviceProcessInstaller1
End With
serviceInstaller1.Install(New Hashtable)
|