【发布时间】:2012-01-23 02:06:42
【问题描述】:
我正在尝试关闭并启动远程计算机(在同一网络上)上的 sql 服务器,我使用了此代码
ConnectionOptions options = new ConnectionOptions();
options.Username = userName;
options.Password = password;
ManagementScope scope =
new ManagementScope(
string.Format(@"\\{0}\root\cimv2", serverFullName),
options);
scope.Connect();
ObjectQuery query = new ObjectQuery(
string.Format(@"SELECT * FROM Win32_Process WHERE Name='{0}'",
processToTerminate));
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
m.InvokeMethod("Terminate", null);
}
- 还有其他方法吗?
- 如何启动进程(如果 Terminate 关闭它)?
谢谢
【问题讨论】:
标签: c# process windows-services remote-access