visor Posted November 5, 2008 Share Posted November 5, 2008 I'm obviously not using the correct search terms and cannot find the answer to the following question: I have a shortcut where the target is something like "c:\Program Files\Application\app.exe /w=1234" I want to know if AutoIt can read the target and extract the /w=1234 part. I know how to reconstruct a new shortcut. Thanks in advance. Link to comment Share on other sites More sharing options...
visor Posted November 5, 2008 Author Share Posted November 5, 2008 I'm obviously not using the correct search terms and cannot find the answer to the following question:I have a shortcut where the target is something like "c:\Program Files\Application\app.exe /w=1234"I want to know if AutoIt can read the target and extract the /w=1234 part. I know how to reconstruct a new shortcut.Thanks in advance.I'm guessing that FileGetShortcut will help - but how do I go about extracting the /w=1234 part from the resultant input? Link to comment Share on other sites More sharing options...
Goblin Posted November 5, 2008 Share Posted November 5, 2008 (edited) Use ShellExecute("c:\Program Files\Application\app.exe","/w=1234") Edited November 5, 2008 by Goblin Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 5, 2008 Share Posted November 5, 2008 $array = FileGetShortcut("myfile.lnk") ;$array[0] = Shortcut target path ;$array[1] = Working directory ;$array[2] = Arguments ;$array[3] = Description ;$array[4] = Icon filename ;$array[5] = Icon index ;$array[6] = The shortcut state (@SW_SHOWNORMAL, @SW_SHOWMINNOACTIVE, @SW_SHOWMAXIMIZED) MsgBox(0, "Command line parameters", $array[2]) Link to comment Share on other sites More sharing options...
visor Posted November 5, 2008 Author Share Posted November 5, 2008 (edited) To clarify, the shortcut I'm reading from is actually on a desktop - not an actual application. I'm now thinking that StringSplit may help me with my task. Possibly something like this: $scTAR = FileGetShortcut ( @DesktopDir & "\app.lnk" ) $stationID = StringSplit($scTAR[0], "/w=") FileCreateShortcut(@ProgramsDir & "\Application\app.exe", @DesktopDir & "\BCP.lnk", @ProgramsDir & "\Application","/w=" & $stationID, "Replacement Backup Link", @SW_SHOWNORMAL) Does anyone else agree? Can anyone offer a better solution? Thanks in advance. Edited November 5, 2008 by visor Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 5, 2008 Share Posted November 5, 2008 (edited) FileGetShortcut returns an array. The third index [2] contains the arguments. The path DOES NOT contain the arguments. $stationID = StringSplit($scTAR[0], "/w=") should be $stationID = StringSplit($scTAR[2], "/w=") $stationID = $stationID[1] Edited November 5, 2008 by Richard Robertson Link to comment Share on other sites More sharing options...
visor Posted November 5, 2008 Author Share Posted November 5, 2008 FileGetShortcut returns an array. The third index [2] contains the arguments. The path DOES NOT contain the arguments. $stationID = StringSplit($scTAR[0], "/w=") should be $stationID = StringSplit($scTAR[2], "/w=") $stationID = $stationID[1] Yes - I can see where I slipped up there, and I completely missed the array part of StringSplit. I'll give that a shot tomorrow - thanks very much for your help. Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 5, 2008 Share Posted November 5, 2008 It's alright. Link to comment Share on other sites More sharing options...
visor Posted November 6, 2008 Author Share Posted November 6, 2008 Just in case this is useful to anyone else... ; *** v1.0 Script to change target to reflect BCP Location *** if not IsAdmin () Then RunAs("admin", "domain", "password", 0, @ScriptName, @ScriptDir, @SW_ENABLE) Exit EndIf If FileExists ( @DesktopDir & "\icon.lnk" ) Then $scTAR = FileGetShortcut ( @DesktopDir & "\icon.lnk" ) $stationID = StringSplit($scTAR[2],"/w=", 1) $stationID = StringSplit($stationID[2]," /") $stationID = $stationID[1] FileCreateShortcut($scTAR[0], @DesktopDir & "\BCP.lnk", $scTAR[1],"/notifier=servername /w=" & $stationID & " /persistent", "BCP Location", @SW_SHOWNORMAL) Else ; Throw an error message about the missing link MsgBox (4096, Default, "Icon does not exist - please contact IT Support with this information.") Exit EndIf '/w=' is taken as individual delimiters, so if you have those characters anywhere in the string, a split will occur. Putting the flag '1' at the end of the line takes them all as a delimiter instead, allowing for the correct break to occur. Thanks for your help chaps. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now