Sign in to follow this  
Followers 0
matrixnz

Help with FileCreateShortcut

2 posts in this topic

Hi there

Not sure exactly what the problem is, but, I'm trying to change old shortcuts paths to new shortcut paths example D:\ to E:\ so I wrote the code below, but for some reason, when creating the new shortcut, the target path is always truncated to an 8 character naming convention so for example C:\Program Files becomes E:\Program_\ the working directory and all others are fine. The strange thing is if I uncomment the MsgBox below, I do get the full path that I want for example E:\Program Files\... it's only when I try to use it along with FileCreateShortcut.

I tried using quotes '"' & $SC_TARGET & '"' still with no joy, so I'm stumped.

Can anyone help?

Cheers

#Include <File.au3>

$SC_DRVOLD = "D:"
$SC_DRVNEW = "E:"
$SC_FLDSEL = FileSelectFolder("Please Select a folder.", $SC_DRVOLD, 4)
$SC_FLDARY = _FileListToArray($SC_FLDSEL, "*.lnk", 1)
For $i = 1 To $SC_FLDARY[0]
;Shortcut File Path
    $SC_FILPTH = $SC_FLDSEL & "\" & $SC_FLDARY[$i]
;Get Shortcut File Information
    $SC_FILGET = FileGetShortcut ($SC_FILPTH)
;Shortcut Target Path - Replace Drive Information
    $SC_TARGET = StringReplace($SC_FILGET[0], $SC_DRVOLD, $SC_DRVNEW)
;Shortcut Working Directory - Replace Drive Information
    $SC_WRKDIR = StringReplace($SC_FILGET[1], $SC_DRVOLD, $SC_DRVNEW)
;Shortcut Arguments - Replace Drive Information
    $SC_ARGMNT = StringReplace($SC_FILGET[2], $SC_DRVOLD, $SC_DRVNEW)
;Shortcut Description - Replace Drive Information
    $SC_DSCPTN = StringReplace($SC_FILGET[3], $SC_DRVOLD, $SC_DRVNEW)
;Shorcut Icon Filename - Replace Drive Information
    $SC_ICNFIL = StringReplace($SC_FILGET[4], $SC_DRVOLD, $SC_DRVNEW)
;Shortcut Icon Index
    $SC_ICNIND = $SC_FILGET[5]
;Shortcut State
    $SC_SSTATE = $SC_FILGET[6]
;Overwrite old Shortcut with New Shortcut
;MsgBox(0,'', $SC_TARGET & @CRLF & $SC_FILPTH & @CRLF & $SC_WRKDIR & @CRLF & $SC_ARGMNT & @CRLF & $SC_DSCPTN & @CRLF & $SC_ICNFIL & @CRLF & $SC_ICNIND & @CRLF & $SC_SSTATE)
    FileCreateShortcut($SC_TARGET, $SC_FILPTH, $SC_WRKDIR, $SC_ARGMNT, $SC_DSCPTN, $SC_ICNFIL, -1, $SC_ICNIND, $SC_SSTATE)
Next

MsgBox(32, "Shortcut Replacement Wizard", "Shortcut Replacement Complete")

Share this post


Link to post
Share on other sites



Think I figured it out, I was misguided by AutoIT help which states that: "FileCreateShortcut does not require a valid target..." it seems it does otherwise it truncates, because I'm doing this on behalf of someone else, I don't have an E: Drive, however once I mapped E: to my C: Drive, the shortcuts were created fine. Not sure if this is a bug or just misprint in AutoIT Help.

Talking of the help, if we find errors do we tell anyone about them? For instance while researching above I found one of the example scripts for FileGetShortName was

$a = FileGetShortName(@HomeDrive & "\Program Files")
msgbox(0,"long file name", $a)
;$a is probably "x:\PROGRA~1"

I know the message box title isn't really important to the function, but also know that examples tend to stay around in future releases.

Cheers

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0