Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. using System.Runtime.InteropServices;
  2. using System.Diagnostics;
  3.  
  4. public class ProcessManager
  5. {
  6. [DllImport("user32.dll")]
  7. private static extern bool ShowWindow(IntPtr hWnd, uint windowStyle);
  8.  
  9. [DllImport("user32.dll")]
  10. private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
  11.  
  12. ProcessManager()
  13. {
  14. string processName = "vlc"; /* Your process name here */
  15. SearchProcessAndModifyState(processName);
  16. }
  17.  
  18. void SearchProcessAndModifyState(string targetProcessName)
  19. {
  20. Process specifiedProcess = null;
  21. Process[] processes = Process.GetProcesses();
  22. for (int i = 0; i < processes.Length; i++)
  23. {
  24. Process process = processes[i];
  25. if (process.ProcessName == targetProcessName)
  26. {
  27. specifiedProcess = process;
  28. break;
  29. }
  30. }
  31. if (specifiedProcess != null)
  32. {
  33. ProcessManager.ShowWindow(specifiedProcess.MainWindowHandle, 1u);
  34. ProcessManager.SetWindowPos(specifiedProcess.MainWindowHandle, new IntPtr(-1), 0, 0, 0, 0, 3u);
  35. }
  36. }
  37. }
  38.  
  39. myTopForm.TopMost = true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement