barbossa Posted March 28, 2012 Share Posted March 28, 2012 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now