Доброе время суток.
# Задача: Получить текст командной строки, с которой был запущен чужой процесс. - То есть, мне нужно узнать, с какими параметрами был запущен чужой процесс.
| Код | using System.IO; // Path; using System.Management; // Также это пространство необходимо добавить/подключить в References; ... public static string GetCommandLineFromPID(int iPID) { string Result = string.Empty; // ---- string sQuery = string.Format("SELECT CommandLine FROM Win32_Process WHERE ProcessId = {0}", iPID); // ---- try { using (ManagementObjectSearcher mos = new ManagementObjectSearcher(sQuery)) { foreach (ManagementObject mo in mos.Get()) { Result = mo["CommandLine"].ToString(); } } // ---- Result = Path.GetFullPath(Result); } catch (Exception) { } // ---- return Result; }
|
- Код был переделан, но взят с MSDN.
# Задача: Получить текст командной строки, с которой был запущен наш процесс.
| Код | /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { if (args.Length > 0) { string CommandLine = string.Empty; int start = Application.ExecutablePath.Length + 3; int len = Environment.CommandLine.Length - start; CommandLine = Environment.CommandLine.Substring(start, len); try { CommandLine = Path.GetFullPath(CommandLine ); } catch (Exception) { } } // ---- Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FFMain()); }
|
P.S. -> Может кому-то пригодится. |