Vote count:
0
I am trying to silence system process that seem to go 100% sometimes with my program on; I don't mean to fix that system process but just to silence it. What I tried is:
ManagementObjectSearcher searcher = new ManagementObjectSearcher( "select CommandLine,ProcessId from Win32_Process where Name='svchost.exe'" );
ManagementObjectCollection retObjectCollection = searcher.Get( );
foreach( ManagementObject retObject in retObjectCollection )
if( ( ( string )retObject[ "CommandLine" ] ).Contains( "-k NetworkService" ) ) {
var process = Process.GetProcessById( int.Parse( retObject[ "ProcessId" ].ToString( ) ) );
process.PriorityClass = ProcessPriorityClass.Idle;
process.ProcessorAffinity = new IntPtr( 1 );
}
retObjectCollection.Dispose( );
This code seem to raise null-exception; when I am adding retObject[ "CommandLine" ] != null && in the if's condition and debug it, all the values that produced from the expression retObject[ "CommandLine" ] are just null; when I am changing scvhost.exe to notepad.exe they produce non-null values. Why is that and how I can fix it to fetch system processes' commands line?
asked 24 secs ago
Why ManagementObjectSearcher resulting in null command lines
Aucun commentaire:
Enregistrer un commentaire