The task is to automatically change the target of hundreds of shortcuts, due to changes of server names. I am pretty sure I have seen someone solve this already, but I cannot find the solution any longer, so I gave it a try myself. Unfortunately I am not an experienced AutoIt scripter, so there are some things I still need to sort out. This is what my (messy) script looks like this far:
$old_path = "dokument-2"
$new_path_NT = "pp.tr\dok"
$new_path_9x = "dokument-4"
; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("*.lnk")
; Check if the search was successful
If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")
Exit
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
MsgBox(4096, "File:", $file)
; Read in the path of a shortcut
$details = FileGetShortcut($file)
MsgBox(0, "Path:", $details[0] & @CR & $details[1] & @CR & $details[2] & @CR & _
$details[3] & @CR & $details[4] & @CR & $details[5] & @CR & $details[6])
; Check if shortcut contains old path and replace with new
If StringInStr($details[0], $old_path) And @OSTYPE = "WIN32_NT" Then
StringReplace($details[0], $old_path, $new_path_NT)
If StringInStr($details[1], $old_path) And @OSTYPE = "WIN32_NT" Then
StringReplace($details[1], $old_path, $new_path_NT)
EndIf
; Send current shortcut to recycle bin if contains path to change
MsgBox(0, "Delete", $file)
; FileRecycle($file)
; Create new shortcut with new path
; FileCreateShortcut($details[0], $file, $details[1])")
EndIf
WEnd
; Close the search handle
FileClose($search)
1. At the moment the script only looks for shortcuts in the current folder. How do I make it search all shortcuts in a harddisk or in a server?
2. I'm insecure about how FileCreateShortcut works. Can I somehow give the full $details-array to preserve all contents? If so, what should it look like?
3. I need to give different paths depending on OS-type, and I feel I do it in a very clumsy way. Any suggestions on better ways to do it? (I've only put NT in code yet, but will repeat it with a different if-statement.)
Cheers!