What changes would have to be made to this batch file to run from the root directory and include all sub-directories?
That one is pretty simple, assuming that by "the root directory" you mean c:\, just replace:
dir /s /b *.lnk
dir /s /b c:\*.lnk
What changes would have to be made to this batch file to selectively find and replace text in the Start in: and Comment: fields? (Maybe some kind of user screen input?)
Here's the syntax from shortcut.exe, which you can get by running it with no parameter:
Shortcut [Version 1.11]
Creates, modifies or queries Windows shell links (shortcuts)
The syntax of this command is:
shortcut /F:filename /A:C|E|Q [/T:target] [/P:parameters] [/W:workingdir]
[/R:runstyle] [/I:icon,index] [/H:hotkey] [/D:description]
/F:filename : Specifies the .LNK shortcut file.
/A:action : Defines the action to take (C=Create, E=Edit or Q=Query).
/T:target : Defines the target path and file name the shortcut points to.
/P:parameters : Defines the command-line parameters to pass to the target.
/W:working dir : Defines the working directory the target starts with.
/R:run style : Defines the window state (1=Normal, 3=Max, 7=Min).
/I:icon,index : Defines the icon and optional index (file.exe or file.exe,0).
/H:hotkey : Defines the hotkey, a numeric value of the keyboard shortcut.
/D:description : Defines the description (or comment) for the shortcut.
- Any argument that contains spaces must be enclosed in "double quotes".
- If Query is specified (/A:Q), all arguments except /F: are ignored.
- To find the numeric hotkey value, use Explorer to set a hotkey and then /A:Q
- To prevent an environment variable from being expanded until the shortcut
is launched, use the ^ carat escape character like this: ^%WINDIR^%
/f:"%ALLUSERSPROFILE%\Start Menu\Programs\My App.lnk" /a:q
/f:"%USERPROFILE%\Desktop\Notepad.lnk" /a:c /t:^%WINDIR^%\Notepad.exe /h:846
/f:"%USERPROFILE%\Desktop\Notepad.lnk" /a:e /p:C:\Setup.log /r:3
An argument of /? or -? displays this syntax and returns 1.
A successful completion will return 0.
Copyright 2000-2005 Marty List, www.OptimumX.com
and what it's output looks like when querying an existing shortcut:
TargetPath=C:\Program Files (x86)\Mozilla Firefox\firefox.exe
TargetPathExpanded=C:\Program Files (x86)\Mozilla Firefox\firefox.exe
WorkingDirectory=C:\Program Files\Mozilla Firefox
WorkingDirectoryExpanded=C:\Program Files\Mozilla Firefox
IconLocationExpanded=C:\Program Files (x86)\Mozilla Firefox\firefox.exe,0
The command completed successfully.
To explain, the current version of the batch :
- lists all of the .lnk files (from where it is being called, including sub-directories due to the /s in the dir command)
- for each element in that list, it :
- uses shortcut.exe to query the file's properties
- uses findstr to filter the output, looking for the characteristic we want to find in the files that we want to act on (here it was "RunStyle=1")
- if the file does match that characteristic, it uses shortcut.exe again to perform the change that has been requested (here it was to set RunStyle to 3)
Could this batch file be incorporated into an .exe file to allow a slick User Interface for the user to search, sort, and select .lnk files and then process/edit them? (I’m thinking this .exe file would probably have to include the code from the shortcut.exe file.)
Not in its current state as doesn't take any input: both the selection criteria and the action to be performed are "hardcoded" in the script.
It would need to be reworked to accept parameters (or ask the user to input them) for which characteristics the files to be modified need to exhibit, and what has to be changed in them, and then pass the adequate parameters to shortcut.exe
I'm not sure I'm up to the task, probably better to wait for one of the real programmers here to do their own thing
Finally, what about URL files? Can they be included in the same software or would that be a separate program?
Shortcut.exe doesn't handle them, they don't work the same as .LNK files and don't have the same set of capabilities (as far as I know they don't allow, for example, to choose if the browser's window will be a normal one, maximized or minimized).
By the way there seems to be a bug with shortcut.exe itself, as the TargetPath and TargetPathExpanded values that I showed in my example are incorrect: I have the 64 bits version of Firefox and it sits in "C:\Program Files\Mozilla Firefox", I don't know where those "(x86)" came from…