Hello J,
Thanks for your post.
If my understanding is correct, you are going to pass custom user
credentails to a windows service while installation or on your own UI.
Generally, we will do it via installation. After that, user can change the
credentials from service management console. There are two ways for user to
input credentials while installation:
1. Pass from command line
Pass the command line argument to service when install the service by
InstallUtil. The command line should look like:
InstallUtil.exe MyService.exe /username=MyUserName /password=Password
In the ProjectInstaller's event OnBeforeInstall, get the credentails and
pass it to ServiceProcessInstaller. Here is the sample code:
----------------------------------------------
protected override void OnBeforeInstall(IDictionary savedState)
{
base.OnBeforeInstall(savedState);
String username = GetContextParameter("username");
String password = GetContextParameter("password");
if (!String.IsNullOrEmpty(username))
serviceProcessInstaller1.Username = username;
if (!String.IsNullOrEmpty(password))
serviceProcessInstaller1.Password = password;
}
----------------------------------------------
For more information, please visit the following blog:
http://menet.name/blog/christophe/archive/2009/03/01/provide-credentials-use
rname-and-password-while-installing-a-service-silently.aspx
2. Pass from Installation UI
This way is similiar with the command line way. The difference is that it
uses MSI to build an UI to pass credentails.
Here are the steps to do it:
1). Create a project installer class that inherits from the Installer class.
Follow the instructions at this link:
http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstall
er.aspx
2). Create a setup project in Visual Studio.
Here is an example:
http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
Note: It is required to add the service DLL as custom actions in setup
project.
3). Add UI for user to input credetials and pass it to project installer
class.
Follow the instructions at:
http://www.c-sharpcorner.com/UploadFile/steve_hall/InstallationPromptForServ
iceAccount10172007152711PM/InstallationPromptForServiceAccount.aspx
In addition, changing user credentails after service installation can also
be done in code.
It is usually implmeneted by WMI or P/Invoke in .NET. Please visit the
following link for details:
http://msmvps.com/blogs/siva/archive/2007/04/19/changing-log-on-credentials-
of-windows-service.aspx
There is also a commandline tool sc.exe, which can be used to change
service configuration. For more information, please visit the following
link:
http://technet.microsoft.com/en-us/library/bb490995.aspx
Please let me know if you need more information.
Regards,
Hongye Sun (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within?2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.