Пример #1
0
        public static string GetCommandLineByProcessId(int processId)
        {
            string result = string.Empty;

            ManagementObjectSearcher managementObjectSearcher = null;

            try
            {
                managementObjectSearcher = new ManagementObjectSearcher(string.Format("SELECT CommandLine FROM Win32_Process WHERE ProcessId = {0}", processId));

                foreach (ManagementObject managementObject in managementObjectSearcher.Get())
                {
                    try
                    {
                        result = managementObject["CommandLine"].ToString();

                        break;
                    }
                    catch (Exception e)
                    {
                        InternalLogger.Log(e);
                    }
                }
            }
            catch
            {
                result = NativeMethodsHelper.GetCommandLine(processId);
            }
            finally
            {
                if (managementObjectSearcher != null)
                {
                    managementObjectSearcher.Dispose();
                    managementObjectSearcher = null;
                }
            }

            return(result);
        }