Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- SET "BATDIR=%~dp0"
- SET "BATFILE=%~nx0"
- CALL SET BATDIR=%%BATDIR:~0,-1%%
- IF NOT EXIST "%BATDIR%\%BATFILE%" (
- echo BATDIR/BATFILE Variable Error
- exit /b 1
- )
- IF NOT EXIST "%BATDIR%\SetUserFTA.exe" (
- echo Missing "%BATDIR%\SetUserFTA.exe"
- exit /b 1
- )
- IF NOT EXIST "%BATDIR%\GetUserFTA.exe" (
- echo Missing "%BATDIR%\GetUserFTA.exe"
- exit /b 1
- )
- SET WINVER=
- for /f "tokens=3" %%A IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "ReleaseID" /reg:64') DO (
- IF NOT "%%A"=="" SET "WINVER=%%A"
- )
- IF EXIST "%USERPROFILE%\%WINVER%_default_apps.txt" exit /b 0
- REM NOTE FOR FUTURE SELF--
- REM COULDNT FIGURE OUT HOW TO PROPERLY QUOTE THE BATDIR HERE
- REM SO DOING IT WITHOUT QUOTES SINCE I CAN RIGHT NOW (no spaces in path)
- SET PDF_APPX=0
- for /f "tokens=*" %%A in ('%BATDIR%\GetUserFTA.exe ^| find /i ".pdf,"') DO (
- echo %%A|find /i "AppX"
- IF NOT ERRORLEVEL 1 SET PDF_APPX=1
- )
- IF /i "%~1"=="minimal" (
- IF "%PDF_APPX%"=="0" GOTO complete
- )
- SET /A "RETRIES=1"
- :set_defaults
- set /a "RETRIES=RETRIES+1"
- IF %RETRIES% GTR 6 (
- echo Retry limit reached.
- exit /b 1
- )
- "%BATDIR%\SetUserFTA.exe" http IE.HTTP
- "%BATDIR%\SetUserFTA.exe" https IE.HTTPS
- "%BATDIR%\SetUserFTA.exe" .htm IE.AssocFile.HTM
- "%BATDIR%\SetUserFTA.exe" .html IE.AssocFile.HTM
- if exist "c:\Program Files (x86)\Microsoft Office\Office16\OUTLOOK.EXE" "%BATDIR%\SetUserFTA.exe" mailto Outlook.URL.mailto.15
- SET ACROBAT_PRO=
- SET ACROBAT_READER=
- for /f "tokens=1" %%A IN ('reg query HKEY_CLASSES_ROOT\.pdf\OpenWithProgids') DO (
- echo %%A|find /i "Acrobat" >nul
- IF NOT ERRORLEVEL 1 SET "ACROBAT_PRO=%%A"
- echo %%A|find /i "AcroExch" >nul
- IF NOT ERRORLEVEL 1 SET "ACROBAT_READER=%%A"
- )
- IF NOT "%ACROBAT_PRO%"=="" (
- "%BATDIR%\SetUserFTA.exe" .pdf %ACROBAT_PRO%
- ) ELSE (
- IF NOT "%ACROBAT_READER%"=="" "%BATDIR%\SetUserFTA.exe" .pdf %ACROBAT_READER%
- )
- IF EXIST "c:\config\DefaultApps.xml" (
- CALL:set_assoc "c:\config\DefaultApps.xml"
- ) ELSE (
- IF EXIST "%BATDIR%\DefaultApps.xml" (
- REM CALL:set_assoc "%BATDIR%\DefaultApps.xml"
- )
- )
- SET PDF_MATCH=0
- SET HTM_MATCH=0
- SET HTTP_MATCH=0
- echo.
- echo Waiting 30 seconds to see if defaults change...
- ping localhost -n 30 >nul
- IF NOT "%ACROBAT_READER%"=="" (
- for /f "tokens=3" %%B IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice" /v "ProgId"') DO (
- echo "%%B"|find /i "%ACROBAT_READER%"
- IF NOT ERRORLEVEL 1 SET PDF_MATCH=1
- )
- ) ELSE (
- SET PDF_MATCH=1
- )
- for /f "tokens=3" %%B IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.htm\UserChoice" /v "ProgId"') DO (
- echo "%%B"|find /i "IE.AssocFile.HTM"
- IF NOT ERRORLEVEL 1 SET HTM_MATCH=1
- echo "%%B"|find /i "htmlfile"
- IF NOT ERRORLEVEL 1 SET HTM_MATCH=1
- )
- for /f "tokens=3" %%B IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" /v "ProgId"') DO (
- echo "%%B"|find /i "IE.HTTP"
- IF NOT ERRORLEVEL 1 SET HTTP_MATCH=1
- )
- IF "%PDF_MATCH%"=="0" (
- echo PDF Changed. Executing again...
- GOTO set_defaults
- )
- IF "%HTM_MATCH%"=="0" (
- echo HTM Changed. Executing again...
- GOTO set_defaults
- )
- IF "%HTTP_MATCH%"=="0" (
- echo HTTP Changed. Executing again...
- GOTO set_defaults
- )
- :complete
- IF NOT "%~1"=="" (
- echo %~1>"%USERPROFILE%\%WINVER%_default_apps.txt"
- ) ELSE (
- echo done>"%USERPROFILE%\%WINVER%_default_apps.txt"
- )
- attrib +h "%USERPROFILE%\%WINVER%_default_apps.txt"
- GOTO END
- :set_assoc
- REM NOTE FOR FUTURE SELF--
- REM COULDNT FIGURE OUT HOW TO PROPERLY QUOTE THE BATDIR HERE
- REM SO DOING IT WITHOUT QUOTES SINCE I CAN RIGHT NOW (no spaces in path)
- for /f "tokens=1 delims=," %%A in ('%BATDIR%\GetUserFTA.exe ^| find /i "AppX"') DO (
- for /f delims^=^"^ tokens^=1-5* %%B in ('type %1 ^| find /i "%%A"') DO (
- echo %%E | find /i "AppX" >nul
- IF ERRORLEVEL 1 (
- echo setting %%C to %%E
- "%BATDIR%\SetUserFTA.exe" %%C %%E
- )
- )
- )
- exit /b 1
- :END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement