Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: batch / Powershell Pairing for creating Shortcuts with Custom Icons with your own .Ico files
- @Echo off
- ::: [ The full path to the program your creating a shortcut for
- Set "ProgramPath=%~F0"
- ::: ]
- ::: [ The Name you want for your shortcut
- Set "ProgramName=%~n0"
- ::: ]
- ::: [ The full path to your Icon
- Set "IconLocation=%~dp0IconName.ico"
- ::: ]
- ::: [ The directory to create and run the powershell script from.
- Set "RunFrom=%TEMP%"
- ::: ]
- ::: [ Pass the properties to the subroutine to create the shortcut via powershell
- Call :CreateShortcut "%ProgramPath%" "%ProgramName%" "%IconLocation%" "%RunFrom%"
- ::: ]
- Exit /B
- ::: [ Use batch to create and run a powershell script that makes a .Ink file with the desired properties.
- :CreateShortcut <Target Program Path> <Shortcut Name> <Icon Path> <Directory to create powershell file in>
- (
- ECHO # Create a Shortcut with Windows PowerShell
- ECHO $SourceFileLocation = "%~1"
- ECHO $ShortcutLocation = "$env:userprofile\Desktop\%~2.lnk"
- ECHO #New-Object : Creates an instance of a Microsoft .NET Framework or COM object.
- ECHO #-ComObject WScript.Shell: This creates an instance of the COM object that represents the WScript.Shell for invoke CreateShortCut
- ECHO $WScriptShell = New-Object -ComObject WScript.Shell
- ECHO $Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation^)
- ECHO $Shortcut.TargetPath = $SourceFileLocation
- ECHO $Shortcut.IconLocation = "%~3"
- ECHO #Save the Shortcut to the TargetPath
- ECHO $Shortcut.Save(^)
- ) >"%~4\CreateShortcut.ps1"
- ::: - Execute powershell script to create Shortcut on User Desktop
- Powershell.exe -NoProfile -ExecutionPolicy Bypass -File %~4\CreateShortcut.ps1
- Exit /B
- ::: ]
Add Comment
Please, Sign In to add comment