开发者

Run the Windows Service with User Name & Password

I'm writing the windows form program to monitor our in-house windows services. The screenshot is provided for the draft version of that program.

Run the Windows Service with User Name & Password

What I want to do is... I want to pass UserName & Password to run the services from my开发者_StackOverflow中文版 program. I don't know which class or components to use.

I tried to use the following codes, as we used in Installing the services. However, it does not still work. Perhaps, I don't know how to bind the user credential with service controller.

ServiceProcessInstaller serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
            serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User;
            serviceProcessInstaller1.Password = txtPassword.Text;
            serviceProcessInstaller1.Username = txtUserName.Text;

So, Please advise me how could I achieve my requirements? Thanks.


Have a look at this library which lets you do just that:

Install a Windows Service in a smart way instead of using the Windows Installer MSI package


Since you are trying to manipulate the account that an existing, installed service is running under, you will need to use the code specified in the following article:

http://weblogs.asp.net/avnerk/archive/2007/05/08/setting-windows-service-account-c-and-wmi.aspx

Basically, the author found that it wasn't as simple as expected but it was possible (without a registry modification).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜