Skip to content

Instantly share code, notes, and snippets.

@hoppfrosch
Last active September 25, 2015 05:30
Show Gist options
  • Save hoppfrosch/a658a480f6c09811c84a to your computer and use it in GitHub Desktop.
Save hoppfrosch/a658a480f6c09811c84a to your computer and use it in GitHub Desktop.
Args.ahk - Returns command line parameters as array
Args( CmdLine := "", Skip := 0 ) { ; By SKAN, http://goo.gl/JfMNpN, CD:23/Aug/2014 | MD:24/Aug/2014
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 )
}
#Warn
#SingleInstance, Force
CmdLine := DllCall( "GetCommandLine", "Str" )
Skip := ( A_IsCompiled ? 1 : 2 )
argv := Args( CmdLine, Skip )
Msgbox % "Count = " argv[0] "`n1=" argv[1] "`n2=" argv[2] "`n3=" argv[3] "`n4=" argv[4] "`n5=" argv[5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment