Thanks for your help thus far. I'm not a Batcher or regular user of VBA scripts. I've used PowerShell to generally rename files in bulk before (with mixed results).
I have, gleaning from StackOverflow, edited the following batch file:
Code: Select all
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "C:\TargetFolder\shortcut.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "C:\prog.exe" >> %SCRIPT%
echo oLink.Arguments = "-X ""C:\dll.dll""" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
Running it creates a single shortcut called "shortcut
" and the target argument contains "C:\prog.exe" -X "C:\dll.dll"
, which is 75% correct. Yet it's still missing the final 25% - the file location at the end of the argument.
My questions now are:
- how do I edit sLinkFile so that "shortcut.lnk" is any (all) filenames in the original folder? (i.e. File0001.lnk, File0002.lnk, random_file.lnk, etc.)
- How do I add the file location (C:\Folder\File_0001.bin) at the end of the command line arguments?
- How do I get it to apply all o' this to every file in the original folder? (i.e. create 1000+ shortcuts in one fell swoop)
Flumble wrote:I assume you have no problem making a loop to traverse all the files in a directory. (I used to, but then forgot and right now I can't be arsed to look it up for either batch, powershell or other shell.)
I do have a problem, but I can figure that out later (a cursory skim of stackoverflow suggests I may have significant problems with this, but I'll deal with that later.
Idea 1: use VBScript to create the shortcuts. It might be easiest to create the whole directory walking with a batch/powershell script and only making the link with VBScript.
Code: Select all
'''Call as: cscript makelink.vbs linkfile original
target = WScript.Arguments(0)
source = WScript.Arguments(1)
Set oWS = WScript.CreateObject("WScript.Shell")
Set oLink = oWS.CreateShortcut(target)
oLink.TargetPath = "C:\Prog.exe"
oLink.Arguments = "-CommandLineArgumentX ""C:\SameDLLForAllFiles.dll"" """ & source & """"
' oLink.WorkingDirectory = "might be needed"
That was sort of the idea I was thinking of. I saved that as a vbs and got an error straight of the bat - (Line 1, char 1)