要用WMI的InvokeMethod来重启某个指定服务,如果判断服务在运行,重启这个服务,但是不晓得mo.InvokeMethod后面的命令,谢谢帮助
//重启指定服务
public string RestartService(string serviceName)
{
string strRst =null;
ManagementObject mo = this.managementClass.CreateInstance();
mo.Path = new ManagementPath(this.strPath+".Name=\""+serviceName+"\"");
try
{
//重启
if((string)mo["State"]=="Running")
mo.InvokeMethod("RestartService",null);//这句有问题(RestartService是我自己写的,不对)
}
catch (System.Exception e)
{
strRst =e.Message;
}
return strRst;
}
//重启指定服务
public string RestartService(string serviceName)
{
string strRst =null;
ManagementObject mo = this.managementClass.CreateInstance();
mo.Path = new ManagementPath(this.strPath+".Name=\""+serviceName+"\"");
try
{
//重启
if((string)mo["State"]=="Running")
mo.InvokeMethod("RestartService",null);//这句有问题(RestartService是我自己写的,不对)
}
catch (System.Exception e)
{
strRst =e.Message;
}
return strRst;
}
Win32_Service
Properties:
AcceptPause
AcceptStop
Caption
CheckPoint
CreationClassName
Description
DesktopInteract
DisplayName
ErrorControl
ExitCode
InstallDate
Name
PathName
ProcessId
ServiceSpecificExitCode
ServiceType
Started
StartMode
StartName
State
Status
SystemCreationClassName
SystemName
TagId
WaitHint
Methods:
StartService
StopService
PauseService
ResumeService
InterrogateService
UserControlService
Create
Change
ChangeStartMode
Delete
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
ManagementClass mc=new ManagementClass("Win32_Service");
mc.Properties//属性集
mc.Methods//方法集