-
Notifications
You must be signed in to change notification settings - Fork 72
/
ShellRun.ahk
57 lines (46 loc) · 2.22 KB
/
ShellRun.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;====================================== EXAMPLE ==================================================
;ShellRun("Taskmgr.exe") ;Task manager
;ShellRun("Notepad", A_ScriptFullPath) ;Open a file with notepad
;ShellRun("Notepad",,,"RunAs") ;Open untitled notepad as administrator
/*===================================================================================================
ShellRun by Lexikos
requires: AutoHotkey_L
license: http://creativecommons.org/publicdomain/zero/1.0/
Credit for explaining this method goes to BrandonLive:
http://brandonlive.com/2008/04/27/getting-the-shell-to-run-an-application-for-you-part-2-how/
Shell.ShellExecute(File [, Arguments, Directory, Operation, Show])
http://msdn.microsoft.com/en-us/library/windows/desktop/gg537745
Parameters for ShellRun
1 application to launch
2 command line parameters
3 working directory for the new process
4 "Verb" (For example, pass "RunAs" to run as administrator)
5 Suggestion to the application about how to show its window - see the msdn link for possible values
*/
ShellRun(prms*)
{
shellWindows := ComObjCreate("{9BA05972-F6A8-11CF-A442-00A0C90A8F39}")
desktop := shellWindows.Item(ComObj(19, 8)) ; VT_UI4, SCW_DESKTOP
; Retrieve top-level browser object.
if ptlb := ComObjQuery(desktop
, "{4C96BE40-915C-11CF-99D3-00AA004AE837}" ; SID_STopLevelBrowser
, "{000214E2-0000-0000-C000-000000000046}") ; IID_IShellBrowser
{
; IShellBrowser.QueryActiveShellView -> IShellView
if DllCall(NumGet(NumGet(ptlb+0)+15*A_PtrSize), "ptr", ptlb, "ptr*", psv:=0) = 0
{
; Define IID_IDispatch.
VarSetCapacity(IID_IDispatch, 16)
NumPut(0x46000000000000C0, NumPut(0x20400, IID_IDispatch, "int64"), "int64")
; IShellView.GetItemObject -> IDispatch (object which implements IShellFolderViewDual)
DllCall(NumGet(NumGet(psv+0)+15*A_PtrSize), "ptr", psv
, "uint", 0, "ptr", &IID_IDispatch, "ptr*", pdisp:=0)
; Get Shell object.
shell := ComObj(9,pdisp,1).Application
; IShellDispatch2.ShellExecute
shell.ShellExecute(prms*)
ObjRelease(psv)
}
ObjRelease(ptlb)
}
}