Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X


Portable app shortcut creator

  • Please log in to reply
No replies to this topic

#1 barbossa



  • Normal Members
  • 6 posts

Posted 28 March 2012 - 07:21 PM

I think most people that use portable USB drives have this problem: the shortcuts to your portable apps get messed up whenever the drive letter changes.

I made this small (and hopefully useful) script to deal with the problem. It generates and compiles an AutoIT Script that calls your app with the relative paths inside your drive, also passing any command line parameter (for example, drag&dropping files on the shortcut) to the portable application.

It has no GUI, only two Open File dialogs, one for you to choose your executable, and other for choosing the shortcut icon, automatically extracted from the executable file using the ExtractIconToFile UDF.

Since the script uses AutoIT itself to compile the shortcut, you must also place Aut2exe.exe, AutoItSC.bin and upx.exe on the script folder.

If you find any bugs, corrections or suggestions, please let me know.

Here is the code for the shortcut creator:

#include <WinAPI.au3> #include "ExtractIconToFile.au3" Dim $exeFilePath Dim $icoFilePath Dim $tmpFolderPath Dim $fileHandle, $filename Dim $numIcons Dim $i ;choose .exe file $exeFilePath = FileOpenDialog ("Choose your destiny... I mean, your app", StringMid(@ScriptDir, 1, 3), "Executable Files (*.exe)", 3) If @error <> 1 Then $tmpFolderPath = @ScriptDir & "\tmp_portable_app_" & @YEAR & @MON & @MDAY & @HOUR & @MIN DirCreate ($tmpFolderPath) ;extract icon files $numIcons = _WinAPI_ExtractIconEx($exeFilePath, -1, 0, 0, 0) For $i = 1 To $numIcons   $filename = $tmpFolderPath & "\icon_" & $i & ".ico"         _ExtractIconToFile($exeFilePath, $i, $filename)     Next $icoFilePath = FileOpenDialog ("Choose your shortcut icon", $tmpFolderPath, "Icon files (*.ico)", 3) If @error <> 1 Then   $fileHandle = FileOpen ($tmpFolderPath & "\tmp_portable_app.au3", 1)   ;generates autoit code to run the application   ;Run (@ScriptDir & "\_Portable Apps Folder\MyApp\MyApp.exe " & $CmdLineRaw)   FileWriteLine ($fileHandle, 'Run (@ScriptDir & "' & StringMid($exeFilePath, 3) & ' " & $CmdLineRaw)')   FileClose ($fileHandle)   ;compiles the script to a .exe file, with the same name as the portable app .exe   ;on the drive root of where the script is run, with the chosen icon   RunWait (@ScriptDir & '\aut2exe.exe' & _         ' /in "' & $tmpFolderPath & '\tmp_portable_app.au3 ' & '"' & _         ' /out "' & StringMid(@ScriptDir, 1, 3) & StringMid($exeFilePath, StringInStr($exeFilePath, '\', Default, -1)) & '"' & _         ' /icon "' & $icoFilePath & '"')   ;removes temporary folder   DirRemove ($tmpFolderPath, 1) EndIf EndIf

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users