如何启动Windows服务并为其设置用户名和密码? [英] How to Start a windows service and set username and password for it?

查看:294
本文介绍了如何启动Windows服务并为其设置用户名和密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个Windows服务,检查另一个窗口服务以检查它是否正在运行。如果要监视的服务已停止,我需要设置一组给定的用户名和密码并重新启动该服务。是否可以这样做。我尝试了以下代码,但它不起作用。



I have made a windows service that checks on another window service to check if it is running.If the service to be monitored has stopped I need to set a given set of username and password and restart that service.would it be possible to do that.I tried the following code but it doesnt work.

string objPath = string.Format("Win32_Service.Name='{0}'", serviceName);
using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
{
   object[] wmiParams = new object[11];
   wmiParams[6] = username;
   wmiParams[7] = password;
   service.InvokeMethod("Change", wmiParams);
}

推荐答案

是的,您可以设置可以访问该Windows服务的用户名。



在安全标签中。



但是机器的管理员将始终可以访问。
Yes, You can set the username who can access to that windows service.

In security tab.

But administrator of the machine will always have the access.


这篇关于如何启动Windows服务并为其设置用户名和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆