> Hi,
>
[quoted text clipped - 11 lines]
> Thanks,
> Anders
Don't use this method, it's just a bag of bugs, use System.Management (WMI)
instead.
Following snip illustrates how you can get the Processes SessionId from a
remote server:
Check MSDN for more detail on WMI's Win32_Process class.
...
ConnectionOptions co = new ConnectionOptions();;
co.Username = "administrator"; //any account with appropriate privileges
co.Password = "pppppp";
string remMachine = "machineName";
ManagementScope scope = new ManagementScope(@"\\" + remMachine +
@"\root\cimv2", co);
SelectQuery selectQuery = new SelectQuery("Select Name, SessionId
from Win32_Process");
using(ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, selectQuery))
{
foreach (ManagementObject proc in searcher.Get())
Console.WriteLine("{0}, {1}",proc["Name"].ToString(),
proc["SessionId"].ToString());
}
Willy.
Anders Bovin - 27 Oct 2007 12:20 GMT
OK! Will do.
Thanks Willy
> > Hi,
> >
[quoted text clipped - 36 lines]
>
> Willy.
Willy Denoyette [MVP] - 27 Oct 2007 17:08 GMT
> OK! Will do.
>
> Thanks Willy
Note that there is nothing wrong with this method when you have to query the
processes running on a local machine, the bugs I've mentioned are related to
the GetProcesses("remotemachine") method. This method uses an internal API
"NtQuerySystemInformation"
http://msdn2.microsoft.com/en-us/library/ms724509.aspx which by itself
should never be used in production code, as as an *added bonus* the
Framework code added a couple of bugs in the part that marshals the
(undocumented part of) _SYSTEM_PROCESS_INFORMATION structure.
Willy.