forked from Ixiko/AHK-libs-and-classes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShellRunEx.ahk
62 lines (48 loc) · 1.35 KB
/
ShellRunEx.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
58
59
60
61
62
#include <ShellRun>
ShellRunEx(cmdLine, workingDir)
{
cmdLine := EnvVars(cmdLine)
args := Args(cmdLine)
; Extract exe path
exePath := args[1]
if (RegExMatch(exePath, "^\\?[^\/:*?""<>|\r\n%]+\\?$") and FileExist(A_ScriptDir "\" exePath))
{
exePath := A_ScriptDir "\" exePath
}
; Extract params
params =
i := 2
while (i <= args[0])
{
params .= args[i]
if (i <> arg[0])
params .= " "
i++
}
; Run command
ShellRun(exePath, params, workingDir)
}
EnvVars(str)
{
if sz:=DllCall("ExpandEnvironmentStrings", "uint", &str
, "uint", 0, "uint", 0)
{
VarSetCapacity(dst, A_IsUnicode ? sz*2:sz)
if DllCall("ExpandEnvironmentStrings", "uint", &str
, "str", dst, "uint", sz)
return dst
}
return src
}
; By SKAN
; http://goo.gl/JfMNpN,
; CD:23/Aug/2014 | MD:24/Aug/2014
Args( CmdLine := "", Skip := 0 )
{
Local pArgs := 0, nArgs := 0, A := []
pArgs := DllCall( "Shell32\CommandLineToArgvW", "WStr",CmdLine, "PtrP",nArgs, "Ptr" )
Loop % ( nArgs )
If ( A_Index > Skip )
A[ A_Index - Skip ] := StrGet( NumGet( ( A_Index - 1 ) * A_PtrSize + pArgs ), "UTF-16" )
Return A, A[0] := nArgs - Skip, DllCall( "LocalFree", "Ptr",pArgs )
}