你可以嘗試冒充。
http://msdn.microsoft.com/en-us/library/ms998351.aspx
public class Test {
[DllImport("advapi32.dll", SetLastError = true)]
static extern bool LogonUser(string principal, string authority, string password, LogonSessionType logonType, LogonProvider logonProvider, out IntPtr token);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool CloseHandle(IntPtr handle);
enum LogonSessionType : uint {
Interactive = 2,
Network,
Batch,
Service,
NetworkCleartext = 8,
NewCredentials
}
enum LogonProvider : uint {
Default = 0,
WinNT35,
WinNT40, //NTLM
WinNT50 //Kerb or NTLM
}
void DoTest() {
IntPtr token = IntPtr.Zero;
WindowsImpersonationContext user = null;
try {
bool loggedin = LogonUser("username", "authority", "password", LogonSessionType.Interactive, LogonProvider.Default, out token);
if (loggedin) {
WindowsIdentity id = new WindowsIdentity(token);
user = id.Impersonate();
Process [] ipByName = Process.GetProcessesByName("notepad", "169.0.0.0");
}
} catch (Exception ex) {
} finally {
if (user != null) {
user.Undo();
}
if (token != IntPtr.Zero) {
CloseHandle(token);
}
}
}
}
如果不工作,你可以嘗試WMI
http://www.codeproject.com/KB/cs/Remote_process_controller.aspx
你有一臺機器的網絡IP地址爲169.0.0.0的? – 2011-01-11 04:43:35