Home All Groups Group Topic Archive Search About
Author
30 Jan 2006 8:32 PM
rayc
I created a simple console program to display process’s pid, caption, and
commandline using (see the source code below). If I compile it and run it
from console, some of process’s commandline is missing. However, if I set the
break point at the end of the program and just run it (F5) with debugging.
All the porcess’s commandline missed before are appeared. Any one has idea?
Could this be bug on WMI?

Partial result from runtime:
=====================
    1660 XFR.EXE                C:\WINDOWS\system32\cba\xfr.exe
    2004 itnaming.exe
     204 itnode_daemon.exe
    1476 METERW32.EXE           C:\LDClient\meterw32.exe
     912 ntvdm.exe              "C:\WINDOWS\system32\ntvdm.exe" -f -i1 -w -a
C:\WINDOWS\system32\krnl386.exe
    3904 naPrdMgr.exe
    3624 OUTLOOK.EXE            "C:\PROGRA~1\MICROS~3\OFFICE11\OUTLOOK.EXE" 
/recycle

Partial result from debug time:
=======================
    1660 XFR.EXE                C:\WINDOWS\system32\cba\xfr.exe
    2004 itnaming.exe          
"C:\Iona\OrbixE2A-ASP-6.03-StdEd\asp\6.0\bin\itnaming.exe" –ORBprodu…
     204 itnode_daemon.exe     
"C:\Iona\OrbixE2A-ASP-6.03-StdEd\asp\6.0\bin\itnode_daemon.exe" –ORB…
    1476 METERW32.EXE           C:\LDClient\meterw32.exe
     912 ntvdm.exe              "C:\WINDOWS\system32\ntvdm.exe" -f -i1 -w -a
C:\WINDOWS\system32\krnl386.exe
    3904 naPrdMgr.exe           C:\PROGRA~1\NETWOR~1\COMMON~1\naPrdMgr.exe
-Embedding
    3624 OUTLOOK.EXE            "C:\PROGRA~1\MICROS~3\OFFICE11\OUTLOOK.EXE" 
/recycle

Source Code:
===========
string sID, sCaption, sCommandLine;
ManagementObjectSearcher query = null;
ManagementObjectCollection queryCollection = null;

// Get only for my local machine
query = new ManagementObjectSearcher( @"\\.\root\cimv2","SELECT * FROM
Win32_Process");
try

    queryCollection = query.Get();
}
catch(Exception ex)
{
    System.Console.WriteLine("Cannot query processes. " + ex.ToString());
    return;

foreach( ManagementObject mo in queryCollection )
{   
    sID = "";
    sCaption = "";
    sCommandLine = "";

    try { sID = mo["ProcessId"].ToString().Trim(); }
    catch (Exception ex)
    {
        System.Console.WriteLine("Failed to get process id. " + ex.ToString());
        //continue;
    }

    try { sCaption = mo["Caption"].ToString().Trim(); }
    catch (Exception ex)
    {
        System.Console.WriteLine("Failed to get caption. " + ex.ToString());
        //continue;
    }

    object o = null;
    try
    {
        o = mo["CommandLine"];
        if( o != null )
        {
            sCommandLine = o.ToString().Trim();
        }   
    }
    catch (Exception ex)
    {
        System.Console.WriteLine("Failed to get command line. " + ex.ToString());
        //continue;
    }
    System.Console.WriteLine( String.Format("{0,8} {1,-22} {2,-256}",
        sID, sCaption, sCommandLine));
} // end foreach

AddThis Social Bookmark Button