0

I have a folder with 1000 .bin files in. I would like help with finding a PowerShell command to create set of shortcuts to these files with a static set of command line parameters in the shortcut's 'Target', namely a program (C:\prog.exe), an argument (-X), a file (dll.dll) and finally the filename (randomly_named_file.bin)

A shortcut with target arguments

"C:\prog.exe" -X "C:\dll.dll" "C:\folder\file_0001.bin"

If I highlight all the .bin files in the folder and right-click-drag to the target folder and select 'create shortcut here', I get 1000+ shortcuts where in 'Target' it just has the filename. I need to create 1000+ shortcuts all with the same target arguments.

0

Found help elsewhere on The Internet!

Here's a simple, elegant PowerShell script that can bulk create billions of shortcuts and append target arguments to all of them, whilst keeping the filename/location at the end of the set of target arguments:

PS C:\folder\where\files\are\kept>

Get-ChildItem | ForEach-Object {
$original = '"' + $_.FullName + '"'
$link     = 'C:\folder\where\files\are\kept' + $_.BaseName + '.lnk'
$wshell   = New-Object -ComObject WScript.Shell
$shortcut = $wshell.CreateShortcut($link)
$shortcut.TargetPath = 'C:\prog.exe'
$shortcut.Arguments = '-X "C:\dll.dll" ' + $original
$shortcut.Save()
}

It was the + $original bit that I was looking for. Hooray.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.