/installer/Lib/Util.ahk

http://github.com/fincs/SciTE4AutoHotkey · AutoHotKey · 87 lines · 66 code · 12 blank · 9 comment · 6 complexity · 2bb54e88201eba9c55e3e4cc9dc5b9d2 MD5 · raw file

  1. Util_GetAhkPath()
  2. {
  3. RegRead, ov, HKLM, SOFTWARE\AutoHotkey, InstallDir
  4. if !ov && A_Is64bitOS
  5. {
  6. q := A_RegView
  7. SetRegView, 64
  8. RegRead, ov, HKLM, SOFTWARE\AutoHotkey, InstallDir
  9. SetRegView, %q%
  10. }
  11. return ov
  12. }
  13. Util_GetAhkVer()
  14. {
  15. RegRead, ov, HKLM, SOFTWARE\AutoHotkey, Version
  16. if !ov && A_Is64bitOS
  17. {
  18. q := A_RegView
  19. SetRegView, 64
  20. RegRead, ov, HKLM, SOFTWARE\AutoHotkey, Version
  21. SetRegView, %q%
  22. }
  23. return ov
  24. }
  25. Util_GetWinVer()
  26. {
  27. pack := DllCall("GetVersion", "uint") & 0xFFFF
  28. pack := (pack & 0xFF) "." (pack >> 8)
  29. pack += 0
  30. return pack
  31. }
  32. Util_CreateShortcut(Shrt, Path, Descr, Args := "", Icon := "", IconN := "")
  33. {
  34. SplitPath, Path,, Dir
  35. FileDelete, %Shrt%
  36. FileCreateShortcut, %Path%, %Shrt%, %Dir%, %Args%, %Descr%, %Icon%,, %IconN%
  37. }
  38. ; Written by Lexikos.
  39. Util_UserRun(target, args := "")
  40. {
  41. try
  42. _ShellRun(target, args)
  43. catch e
  44. Run, % args="" ? target : target " " args
  45. }
  46. ; Written by Lexikos.
  47. _ShellRun(prms*)
  48. {
  49. shellWindows := ComObjCreate("{9BA05972-F6A8-11CF-A442-00A0C90A8F39}")
  50. ; Find desktop window object.
  51. VarSetCapacity(_hwnd, 4, 0)
  52. desktop := shellWindows.FindWindowSW(0, "", 8, ComObj(0x4003, &_hwnd), 1)
  53. ; Retrieve top-level browser object.
  54. if ptlb := ComObjQuery(desktop
  55. , "{4C96BE40-915C-11CF-99D3-00AA004AE837}" ; SID_STopLevelBrowser
  56. , "{000214E2-0000-0000-C000-000000000046}") ; IID_IShellBrowser
  57. {
  58. ; IShellBrowser.QueryActiveShellView -> IShellView
  59. if DllCall(NumGet(NumGet(ptlb+0)+15*A_PtrSize), "ptr", ptlb, "ptr*", psv:=0) = 0
  60. {
  61. ; Define IID_IDispatch.
  62. VarSetCapacity(IID_IDispatch, 16)
  63. NumPut(0x46000000000000C0, NumPut(0x20400, IID_IDispatch, "int64"), "int64")
  64. ; IShellView.GetItemObject -> IDispatch (object which implements IShellFolderViewDual)
  65. DllCall(NumGet(NumGet(psv+0)+15*A_PtrSize), "ptr", psv
  66. , "uint", 0, "ptr", &IID_IDispatch, "ptr*", pdisp:=0)
  67. ; Get Shell object.
  68. shell := ComObj(9,pdisp,1).Application
  69. ; IShellDispatch2.ShellExecute
  70. shell.ShellExecute(prms*)
  71. ObjRelease(psv)
  72. }
  73. ObjRelease(ptlb)
  74. }
  75. }