WMI error with simple request in C #

I am trying to use this code in Windows 2000:

foreach (Process p in Process.GetProcesses()) { if (p.MainModule.FileName.EndsWith("calc.exe")) { using (ManagementObjectSearcher mos = new ManagementObjectSearcher( "SELECT CommandLine,ExecutablePath FROM Win32_Process WHERE ProcessId=" + p.Id.ToString())) { using (ManagementObjectCollection moc = mos.Get()) { foreach (ManagementObject mo in moc) { MessageBox.Show((string)mo["CommandLine"]); return; } } } } } 

This works in Windows XP and above, but does not work in Windows 2000 with an "Invalid Request" error. According to MSDN , the Win32_Process object is supported on Windows 2000 and above, so I'm not sure what I'm doing wrong. Any help would be greatly appreciated.

+1
source share
1 answer

Sorry everyone. I just realized that the "CommandLine" field is only in Windows XP and above. The problem is resolved.

+1
source

Source: https://habr.com/ru/post/1309546/


All Articles