T3RRYT3RR0R

Batch Shortcut and Icon creator

May 4th, 2020
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.67 KB | None | 0 0
  1. ::: batch / Powershell Pairing for creating Shortcuts with Custom Icons with your own .Ico files
  2.  
  3. @Echo off
  4. ::: [ The full path to the program your creating a shortcut for
  5.     Set "ProgramPath=%~F0"
  6. ::: ]
  7. ::: [ The Name you want for your shortcut
  8.     Set "ProgramName=%~n0"
  9. ::: ]
  10. ::: [ The full path to your Icon
  11.     Set "IconLocation=%~dp0IconName.ico"
  12. ::: ]
  13. ::: [ The directory to create and run the powershell script from.
  14.     Set "RunFrom=%TEMP%"
  15. ::: ]
  16.  
  17. ::: [ Pass the properties to the subroutine to create the shortcut via powershell
  18.     Call :CreateShortcut "%ProgramPath%" "%ProgramName%" "%IconLocation%" "%RunFrom%"
  19. ::: ]
  20.     Exit /B
  21.  
  22. ::: [ Use batch to create and run a powershell script that makes a .Ink file with the desired properties.
  23. :CreateShortcut <Target Program Path> <Shortcut Name> <Icon Path> <Directory to create powershell file in>
  24.     (
  25.     ECHO # Create a Shortcut with Windows PowerShell
  26.     ECHO $SourceFileLocation = "%~1"
  27.     ECHO $ShortcutLocation = "$env:userprofile\Desktop\%~2.lnk"
  28.     ECHO #New-Object : Creates an instance of a Microsoft .NET Framework or COM object.
  29.     ECHO #-ComObject WScript.Shell: This creates an instance of the COM object that represents the WScript.Shell for invoke CreateShortCut
  30.     ECHO $WScriptShell = New-Object -ComObject WScript.Shell
  31.     ECHO $Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation^)
  32.     ECHO $Shortcut.TargetPath = $SourceFileLocation
  33.     ECHO $Shortcut.IconLocation = "%~3"
  34.     ECHO #Save the Shortcut to the TargetPath
  35.     ECHO $Shortcut.Save(^)
  36.     ) >"%~4\CreateShortcut.ps1"
  37. ::: - Execute powershell script to create Shortcut on User Desktop
  38.     Powershell.exe -NoProfile -ExecutionPolicy Bypass -File %~4\CreateShortcut.ps1
  39. Exit /B
  40. ::: ]
Add Comment
Please, Sign In to add comment