Older Version Newer Version

bshipps64 bshipps64 Feb 18, 2006 - "Misc formatting changes"

=GetCommandLineArgs$ sub= An==GetCommandLineArgs$ sub== An example of using the Windows API to retrieve the entire command line, then parsing that lineit to extract just the arguments passed to the executable. Ex: > If ---- If cmdLine$ contains "C:\test.exe /switch", then > C:\test.exe /switch then args$ will be assigned the value "/switch" > If/switch If cmdLine$ contains ""C:\test > "C:\test folder\test.exe" /someSwitch /anotherSwitch", > args$/param1 /param2 -param3 args$ will be assigned "/someSwitch /anotherSwitch" > /param1 /param2 -param3 [[code format="vbnet"]] sub GetCommandLineArgs$ byref args$ q$ q$ = chr$(34) 'API 'API call returns pointer to a string 'containing 'containing command line contents calldll calldll #kernel32, "GetCommandLineA",_ pointer pointer as ulong 'Use 'Use winstring() to actually get the string 'from 'from pointer cmdLine$ = cmdLine$ = trim$(winstring(pointer)) cLen = cLen = len(cmdLine$) 'Extract 'Extract just the arguments from the variable if if (left$(cmdLine$, 1) = q$) then qPos = qPos = instr(cmdLine$, q$, 2) args$ = args$ = trim$(right$(cmdLine$, cLen - qPos)) else pLen = else pLen = len(word$(cmdLine$,1)) args$ = args$ = trim$(right$(cmdLine$, cLen - pLen)) end end if end sub [[code]]