Portable Apps without tools

Discussion in 'Interesting/Unrelated' started by Glenn, May 16, 2023.

  1. Glenn

    Glenn Administrator Staff Member

    Making apps or games portable is always a fun job... I figured out a easy way to fake an app being installed while trying to make minecraft fully portable, instead of copying to %AppData%

    Code:
    :::::::::::::::::::::::::::::::::::::::::
    :: Automatically check & get admin rights
    :::::::::::::::::::::::::::::::::::::::::
    @echo off
    CLS
    ECHO.
    ECHO =============================
    ECHO Running Admin shell
    ECHO =============================
    :checkPrivileges
    NET FILE 1>NUL 2>NUL
    if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
    :getPrivileges
    if '%1'=='ELEV' (shift & goto gotPrivileges)
    ECHO.
    ECHO **************************************
    ECHO Invoking UAC for Privilege Escalation
    ECHO **************************************
    setlocal DisableDelayedExpansion
    set "batchPath=%~0"
    setlocal EnableDelayedExpansion
    ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
    ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
    "%temp%\OEgetPrivileges.vbs"
    exit /B
    :gotPrivileges
    ::::::::::::::::::::::::::::
    ::START
    ::::::::::::::::::::::::::::
    setlocal & pushd .
    REM put here code as you like
    ren %AppData%\.minecraft minecraftbackup >nul
    mklink /D "%AppData%\.minecraft" "%~dp0.minecraft"
    reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%AppData%\.minecraft\minecraft launcher\Minecraft Launcher.exe" /t REG_SZ /d "~ PERPROCESSSYSTEMDPIFORCEOFF HIGHDPIAWARE" /f
    start "" "%AppData%\.minecraft\minecraft launcher\Minecraft Launcher.exe"
    rd /q %AppData%\.minecraft
    ren %AppData%\minecraftbackup .minecraft>nul
    
    The code is below the "REM put here code as you like" line, but you need to remember to set the .cmd to be ran as admin, you could in theory use a SFX to do the same job, but I really wanted to just post how using mklink can link to a physical folder on another drive and any reads or writes to that folder will be to the folder/drive your on, in my case D:\ppGames\Minecraft, but as minecraft forced users to install to "%AppData%\.MineCraft" I just wanted to save the copy from happening and in turn, figured it would work for any app that uses the %AppData% etc, just try to use deeper sub folders as using %AppData%\Adobe would make other Adobe apps access the portable app, instead try to keep them deeper in the folders... As you can see it will clean itself up once you quit the app, but if you run them both at the same time, you could end up with excess files and other apps complaining about missing files.

    Oh and the reg link is just in there to disable DPI, as minecraft seamed to be bigger than the screen as I use 125% DPI. this fixes that too.
     
    Last edited: May 16, 2023

Share This Page