Windows Develop Bookmark and Share   
 index > Windows Forms General > Set service logon problem - Windows service
 

Set service logon problem - Windows service

Hi,

I'm developing a Windows Service in VB.Net and set the Account property of the ServiceProcessInstaller as "User", which is my security requirement. So whenever I tried to install the service using INSTALLUTIL.exe, it is prompting to enter user id and password information. To avoid that I have written below code:

PublicOverridesSubInstall(ByValstateSaverAsSystem.Collections.IDictionary)
Try
Upload_ServiceProcessInstaller.Username="Srikanth"
Upload_ServiceProcessInstaller.Password="C))lB0y"
MyBase.Install(stateSaver)
CatchArgExAsArgumentException
LogError_ErrorLog("ArgumentExceptioninInstall()methodofProjectInstaller.vb"&ArgEx.Message.ToString()&vbCrLf&ArgEx.InnerException.ToString())
CatchexAsException
LogError_ErrorLog("ErrorinInstall()methodofProjectInstaller.vb"&ex.Message.ToString()&vbCrLf&ex.InnerException.ToString())
EndTry
EndSub


This is working fine. But now my requirement is to get the user name and password from the config file. So I have updated the above code like shown below:

ImportsSystem.Configuration
PublicOverridesSubInstall(ByValstateSaverAsSystem.Collections.IDictionary)
Try
Upload_ServiceProcessInstaller.Username=System.Configuration.ConfigurationManager.AppSettings("ServiceUser").ToString()
Upload_ServiceProcessInstaller.Password=System.Configuration.ConfigurationManager.AppSettings("ServiceUserPassword").ToString()
MyBase.Install(stateSaver)
CatchArgExAsArgumentException
LogError_ErrorLog("ArgumentExceptioninInstall()methodofProjectInstaller.vb"&ArgEx.Message.ToString()&vbCrLf&ArgEx.InnerException.ToString())
CatchexAsException
LogError_ErrorLog("ErrorinInstall()methodofProjectInstaller.vb"&ex.Message.ToString()&vbCrLf&ex.InnerException.ToString())
EndTry
EndSub


Compiled the code and tried to install the service using INSTALLUTIL but getting below errors:

1 Microsoft(R).NETFrameworkInstallationutilityVersion2.0.50727.1433
2 Copyright(c)MicrosoftCorporation.Allrightsreserved.
3
4
5 Runningatransactedinstallation.
6
7 BeginningtheInstallphaseoftheinstallation.
8 SeethecontentsofthelogfilefortheC:\ProgramFiles\TFSUpload\TFSUpload.exeassembly'sprogress.
9 ThefileislocatedatC:\ProgramFiles\TFSUpload\TFSUpload.InstallLog.
10 Installingassembly'C:\ProgramFiles\TFSUpload\TFSUpload.exe'.
11 Affectedparametersare:
12 logtoconsole=
13 assemblypath=C:\ProgramFiles\TFSUpload\TFSUpload.exe
14 logfile=C:\ProgramFiles\TFSUpload\TFSUpload.InstallLog
15
16 AnexceptionoccurredduringtheInstallphase.
17 System.NullReferenceException:Objectreferencenotsettoaninstanceofanobject.
18
19 TheRollbackphaseoftheinstallationisbeginning.
20 SeethecontentsofthelogfilefortheC:\ProgramFiles\TFSUpload\TFSUpload.exeassembly'sprogress.
21 ThefileislocatedatC:\ProgramFiles\TFSUpload\TFSUpload.InstallLog.
22 Rollingbackassembly'C:\ProgramFiles\TFSUpload\TFSUpload.exe'.
23 Affectedparametersare:
24 logtoconsole=
25 assemblypath=C:\ProgramFiles\TFSUpload\TFSUpload.exe
26 logfile=C:\ProgramFiles\TFSUpload\TFSUpload.InstallLog
27 AnexceptionoccurredduringtheRollbackphaseoftheTFSUpload.ProjectInstallerinstaller.
28 System.ArgumentException:ThesavedStatedictionarydoesnotcontaintheexpectedvaluesandmighthavebeencorrupted.
29 AnexceptionoccurredduringtheRollbackphaseoftheinstallation.Thisexcept
30 ionwillbeignoredandtherollbackwillcontinue.However,themachinemightnotfullyreverttoitsinitialstateaftertherollbackiscomplete.
31
32 TheRollbackphasecompletedsuccessfully.
33
34 Thetransactedinstallhascompleted.
35 Theinstallationfailed,andtherollbackhasbeenperformed.
36 Theservicenameisinvalid.
37
38 MorehelpisavailablebytypingNETHELPMSG2185.
Read the line numbers 16, 17, 27 & 28 for the error details. And also I'm not getting any error information in the log files (the code is there in the catch block).

Could some one assist me to resolve this issue.

Thanks,
Srikanth
Kakkunuri  Wednesday, February 25, 2009 7:16 AM

Hi Kakkunuri,

I performed a test basedon your description and reproduce the problem on my side.

The NullReferenceException actually occurs from the line of code:

Upload_ServiceProcessInstaller.Username=System.Configuration.ConfigurationManager.AppSettings("ServiceUser").ToString()


This is because the "System.Configuration.ConfigurationManager.AppSettings("ServiceUser")" returns Nothing. Calling any method on Nothing raises the NullReferenceException.

In fact, only WinForm executable application will read from their configuration files. Configuration files doesn't make sense to assemblies other than WinForm executable application.

You have to either input the username and password in the prompt while installing the service or hard code the username and password in the override Install method.

Hope this helps.

Sincerely,
Linda Liu

Linda Liu  Friday, February 27, 2009 9:56 AM

Hi Kakkunuri,

I performed a test basedon your description and reproduce the problem on my side.

The NullReferenceException actually occurs from the line of code:

Upload_ServiceProcessInstaller.Username=System.Configuration.ConfigurationManager.AppSettings("ServiceUser").ToString()


This is because the "System.Configuration.ConfigurationManager.AppSettings("ServiceUser")" returns Nothing. Calling any method on Nothing raises the NullReferenceException.

In fact, only WinForm executable application will read from their configuration files. Configuration files doesn't make sense to assemblies other than WinForm executable application.

You have to either input the username and password in the prompt while installing the service or hard code the username and password in the override Install method.

Hope this helps.

Sincerely,
Linda Liu

Linda Liu  Friday, February 27, 2009 9:56 AM
Hi Sikrath,

please tell us, whats in 'upload'. Thanks

Gerhard
Gerhard  18 hours 21 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• UserControl Questions
• warp rectangle
• Form.ShowDialog
• ResourceManager and Translations
• Drawing see-thru shadows
• controls in vb2005
• CausesValidation problem
• Print directly to dotmatrix printer
• ntdll.dll Issue
• how to get the name of the form running the procedure from a referenced class?