日期:2014-05-18  浏览次数:20870 次

如何用wmi 重启某个服务
要用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;
}

------解决方案--------------------
参考下 ServiceController
------解决方案--------------------
http://msdn.microsoft.com/zh-cn/library/system.serviceprocess.servicecontroller(VS.80).aspx
------解决方案--------------------
这是我自己整到的:
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
------解决方案--------------------
http://www.cnblogs.com/ocean2000/archive/2008/07/09/1238944.html
  
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 

http://feiyun0112.cnblogs.com/
------解决方案--------------------
其实很简单:
ManagementClass mc=new ManagementClass("Win32_Service");
mc.Properties//属性集
mc.Methods//方法集
------解决方案--------------------
下载个微软的WMITools软件,用一下就能查到所有的WMI函数和方法了