Advertisement
kazurai

[AHK Lib] SetPriority() ver.200223

Jun 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 【タイトル】SetPriority
  3. 【  概要  】優先度セット
  4. 【  Type  】Lib(関数)
  5. 【  返値  】なし
  6. 【  Site  】http://pastebin.com/TnRd7dmC
  7. 【 更新日 】2020/02/23
  8.  
  9. R│Realtime   │リアルタイム│256
  10. H│High       │高          │128
  11. A│AboveNormal│通常以上    │32768
  12. N│Normal     │通常        │32
  13. B│BelowNormal│通常以下    │16384
  14. L│Low        │低          │64
  15.  
  16. ┌----┐
  17. │関数│
  18. └----┘
  19. SetPriority("ProcessName", "*")     ;優先度セット
  20. SetPriority("ProcessName", "**")    ;優先度セット(Active/NotActive)
  21.  
  22. ■引数(Parameters)
  23. ProcessName│   : プロセス名
  24.        mode│R  : リアルタイム
  25.            │H  : 高
  26.            │A  : 通常以上
  27.            │N  : 通常
  28.            │B  : 通常以下
  29.            │L  : 低
  30.            │** : Active/NotActive (e.g. NB:通常/通常以下)
  31.  
  32. ┌----------┐
  33. │How to Use│
  34. └----------┘
  35. ■使用例
  36.  
  37. */
  38. ;【SetPriority()】
  39.  
  40. SetPriority(ProcessName, mode) {
  41.     Process, Exist, %ProcessName%
  42.     if ErrorLevel {
  43.         ;Get
  44.         PID := ErrorLevel
  45.         hProcess := DllCall("OpenProcess", "UInt", 1024, "Int", 0, "UInt", PID) ;プロセスハンドル取得
  46.         Priority := DllCall("GetPriorityClass", "Ptr", hProcess)                ;優先度取得
  47.         DllCall("CloseHandle", "Ptr", hProcess)                                 ;プロセスハンドル解放
  48.         ;Set
  49.         For i, v in StrSplit(mode) {
  50.             Switch v {
  51.                 Case "R": a%i% := 256  , b%i% := "Realtime"
  52.                 Case "H": a%i% := 128  , b%i% := "High"
  53.                 Case "A": a%i% := 32768, b%i% := "AboveNormal"
  54.                 Case "N": a%i% := 32   , b%i% := "Normal"
  55.                 Case "B": a%i% := 16384, b%i% := "BelowNormal"
  56.                 Case "L": a%i% := 64   , b%i% := "Low"
  57.             }
  58.         }
  59.         if !a2 {
  60.             IfNotEqual, Priority, %a1%, Process, Priority, %ProcessName%, %b1%
  61.         } else {
  62.             if WinActive("ahk_exe " ProcessName) {
  63.                 IfNotEqual, Priority, %a1%, Process, Priority, %ProcessName%, %b1%
  64.             } else {
  65.                 IfNotEqual, Priority, %a2%, Process, Priority, %ProcessName%, %b2%
  66.             }
  67.         }
  68.         ;Notes
  69.         ;要Script Block ※if/else後のIf[Not]Equal
  70.     }
  71. return
  72. }
  73. ;     OpenProcess http://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess/
  74. ;GetPriorityClass http://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getpriorityclass/
  75. ;     CloseHandle http://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement