我正在运行VirtualBox,并希望检索在主机上运行的某个进程。
两者都运行64位版本的Windows 7.我有管理员访问权限,启用了远程共享,添加了两台PC
到一个家庭组,并禁用我的防火墙,但我仍然得到System.InvalidOperationException: 'Couldn't connect to remote machine.'
我已经尝试了GetProcesses
和GetProcessesByName
,两者都抛出相同的异常。
public void StartMainThread()
{
ThreadPool.SetMaxThreads(Environment.ProcessorCount, Environment.ProcessorCount);
for (int i = 0; i < Program.data.Threads; i++)
{
mChildThreads[i] = new PixelThread();
}
ThreadPool.QueueUserWorkItem(delegate (object o) {
this.mRunning = true;
if (Process.GetProcessesByName("notepad", "ipaddress").Length == 0) // exception is thrown here
{
MessageBox.Show("Failed to find window", "Error!");
this.StopThread();
}
else
{
IntPtr mainWindowHandle = Process.GetProcesses("notepad", "ipaddress")[0].MainWindowHandle;
if (mainWindowHandle == IntPtr.Zero)
{
MessageBox.Show("Failed to find window", "Error!");
this.StopThread();
}
else
{
((MainForm)Form.ActiveForm).ProcessStatus("STATUS : Attached", Color.Green);
}
}
});
}
我做错了什么?
答案 0 :(得分:0)
GetProcessByName的第二个参数应该是IP地址。也就是说,要么设置变量并传递它(没有quoutes ),要么直接写入。
string ipaddress = "192.168.1.10";
然后:
Process.GetProcessByName("notepad", ipaddress);