private static bool ProcessCommandLine(Dictionary<string, string> pArgs) { if (pArgs.ContainsKey("-e")) { try { ExtendedCmd.Run(pArgs); } catch (Exception ex) { PhUtils.ShowException("Unable to complete the operation", ex); } return true; } if (pArgs.ContainsKey("-installkph")) { try { using (var scm = new ServiceManagerHandle(ScManagerAccess.CreateService)) { using (var shandle = scm.CreateService( "KProcessHacker", "KProcessHacker", ServiceType.KernelDriver, ServiceStartType.SystemStart, ServiceErrorControl.Ignore, Application.StartupPath + "\\kprocesshacker.sys", null, null, null )) { shandle.Start(); } } } catch (WindowsException ex) { Environment.Exit((int)ex.ErrorCode); } return true; } if (pArgs.ContainsKey("-uninstallkph")) { try { using (var shandle = new ServiceHandle("KProcessHacker", ServiceAccess.Stop | (ServiceAccess)StandardRights.Delete)) { try { shandle.Control(ServiceControl.Stop); } catch { } shandle.Delete(); } } catch (WindowsException ex) { Environment.Exit((int)ex.ErrorCode); } return true; } if (pArgs.ContainsKey("-ip")) InspectPid = int.Parse(pArgs["-ip"]); if (pArgs.ContainsKey("-pw")) { int pid = int.Parse(pArgs["-pw"]); SharedThreadProvider = new SharedThreadProvider(Properties.Settings.Default.RefreshInterval); SecondarySharedThreadProvider = new SharedThreadProvider(Properties.Settings.Default.RefreshInterval); ProcessProvider = new ProcessSystemProvider(); ServiceProvider = new ServiceProvider(); SharedThreadProvider.Add(ProcessProvider); SharedThreadProvider.Add(ServiceProvider); ProcessProvider.RunOnce(); ServiceProvider.RunOnce(); ProcessProvider.Enabled = true; ServiceProvider.Enabled = true; Win32.LoadLibrary(Properties.Settings.Default.DbgHelpPath); if (!ProcessProvider.Dictionary.ContainsKey(pid)) { PhUtils.ShowError("The process (PID " + pid.ToString() + ") does not exist."); Environment.Exit(0); return true; } ProcessWindow pw = new ProcessWindow(ProcessProvider.Dictionary[pid]); Application.Run(pw); SharedThreadProvider.Dispose(); ProcessProvider.Dispose(); ServiceProvider.Dispose(); Environment.Exit(0); return true; } if (pArgs.ContainsKey("-pt")) { int pid = int.Parse(pArgs["-pt"]); try { using (var phandle = new ProcessHandle(pid, Program.MinProcessQueryRights)) Application.Run(new TokenWindow(phandle)); } catch (Exception ex) { PhUtils.ShowException("Unable to show token properties", ex); } return true; } if (pArgs.ContainsKey("-o")) { OptionsWindow options = new OptionsWindow(true) { StartPosition = FormStartPosition.CenterScreen }; IWin32Window window; if (pArgs.ContainsKey("-hwnd")) window = new WindowFromHandle(new IntPtr(int.Parse(pArgs["-hwnd"]))); else window = new WindowFromHandle(IntPtr.Zero); if (pArgs.ContainsKey("-rect")) { Rectangle rect = Utils.GetRectangle(pArgs["-rect"]); options.Location = new Point(rect.X + 20, rect.Y + 20); options.StartPosition = FormStartPosition.Manual; } options.SelectedTab = options.TabPages["tabAdvanced"]; options.ShowDialog(window); return true; } if (pArgs.ContainsKey("")) if (pArgs[""].Replace("\"", "").Trim().ToLower().EndsWith("taskmgr.exe")) StartVisible = true; if (pArgs.ContainsKey("-m")) StartHidden = true; if (pArgs.ContainsKey("-v")) StartVisible = true; if (pArgs.ContainsKey("-a")) { try { Unhook(); } catch { } try { NProcessHacker.KphHookInit(); } catch { } } if (pArgs.ContainsKey("-t")) { if (pArgs["-t"] == "0") SelectTab = "Processes"; else if (pArgs["-t"] == "1") SelectTab = "Services"; else if (pArgs["-t"] == "2") SelectTab = "Network"; } return false; }
private static void LoadProviders() { ProcessProvider = new ProcessSystemProvider(); ServiceProvider = new ServiceProvider(); NetworkProvider = new NetworkProvider(); Program.SharedThreadProvider = new SharedThreadProvider(Properties.Settings.Default.RefreshInterval); Program.SharedThreadProvider.Add(ProcessProvider); Program.SharedThreadProvider.Add(ServiceProvider); Program.SharedThreadProvider.Add(NetworkProvider); Program.SecondarySharedThreadProvider = new SharedThreadProvider(Properties.Settings.Default.RefreshInterval); }