Jump to content

Recommended Posts

Posted

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.

Posted

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?

Posted (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 by visor
Posted (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 by Richard Robertson
Posted

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. :mellow:
Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...