让我解释一下我的问题。 我想在另一台PC上杀死C#窗口应用程序。但是,我的问题是我不知道用户是否打开了儿童表格。在使用WMI通过Remote终止应用程序之前,我需要知道他们是否正在使用Child表单。如果他们正在使用,我无法杀死该应用程序。所以,我想知道如何使用WMI检查远程应用程序的子表单。我的代码在下面 -
private void button1_Click(object sender, EventArgs e)
{
var processName = "VPSBACKEND.exe";
var connectoptions = new ConnectionOptions();
connectoptions.Impersonation = ImpersonationLevel.Impersonate;
connectoptions.Authentication = AuthenticationLevel.Packet;
connectoptions.EnablePrivileges = true;
connectoptions.Username = @"Moe";
connectoptions.Password = "123";
string ipAddress = "192.168.100.95";
ManagementPath path = new ManagementPath(@"\\" + ipAddress + @"\root\cimv2");
ManagementScope scope = new ManagementScope(path, connectoptions);
scope.Connect();
// WMI query
var query = new SelectQuery("select * from Win32_process where name = '" + processName + "'");
using (var searcher = new ManagementObjectSearcher(scope, query))
{
foreach (ManagementObject process in searcher.Get()) // this is the fixed line
process.InvokeMethod("Terminate", null);
}
}