问题
I've got a virtual machine running on Windows 7 called "VirtualXP-12345". I tried using
System.Diagnostics.Process.GetProcesses("VirtualXP-12345")
from the host machine but that doesn't work. I just get InvalidOperationException("Couldn't connect to remote machine.").
I am trying to write a program that checks that a particular process is running on a PC, including all virtual machines also running on that machine. It works fine using Pocess.GetProcesses() on the local non-virtual machine, but I need to determine if the process is running anywhere on the local machine, as it needs to be shut down in order to update files in use.
回答1:
By default you can't connect to a windows 7 machine and get a list of processes. Try turning off the firware in your VM and see if that helps.
回答2:
According to the documentation, you are using the right API call for getting process on another machine (virtual or not doesn't matter).
The error you get back specifies that it is a connectivity issue. To fix that, you should start by checking that:
- Your host machine can map the name to an IP address (test with ping).
- You have basic IP connectivity (test with ping).
- Your virtual machine allows inbound connections on port 445, which is RPC over TCP/IP that is used by all Windows core networking features. (Simple test is to hit start->run and type
\\virtualxp-12345
)
回答3:
Not really sure, but I think you can not, as basically, virtual machnie is like another machine in your LAN. You need that "someone collaborates" with you on its side. In other words some tool, that you can call via network and retrive process list.
Infact during the setup of your machine you set Bridge/NAT/... network type, if you remember, just like if you would like to setup LAN.
Regards.
来源:https://stackoverflow.com/questions/6655375/is-there-a-way-to-get-a-list-of-processes-running-on-a-local-virtual-machine