Advertisement
syntax53

Untitled

Aug 3rd, 2018
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.97 KB | None | 0 0
  1. @echo off
  2.  
  3. SET "BATDIR=%~dp0"
  4. SET "BATFILE=%~nx0"
  5. CALL SET BATDIR=%%BATDIR:~0,-1%%
  6. IF NOT EXIST "%BATDIR%\%BATFILE%" (
  7.     echo BATDIR/BATFILE Variable Error
  8.     exit /b 1
  9. )
  10.  
  11. IF NOT EXIST "%BATDIR%\SetUserFTA.exe" (
  12.     echo Missing "%BATDIR%\SetUserFTA.exe"
  13.     exit /b 1
  14. )
  15. IF NOT EXIST "%BATDIR%\GetUserFTA.exe" (
  16.     echo Missing "%BATDIR%\GetUserFTA.exe"
  17.     exit /b 1
  18. )
  19.  
  20. SET WINVER=
  21. for /f "tokens=3" %%A IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "ReleaseID" /reg:64') DO (
  22.     IF NOT "%%A"=="" SET "WINVER=%%A"
  23. )
  24. IF EXIST "%USERPROFILE%\%WINVER%_default_apps.txt" exit /b 0
  25.  
  26. REM NOTE FOR FUTURE SELF--
  27. REM COULDNT FIGURE OUT HOW TO PROPERLY QUOTE THE BATDIR HERE
  28. REM SO DOING IT WITHOUT QUOTES SINCE I CAN RIGHT NOW (no spaces in path)
  29. SET PDF_APPX=0
  30. for /f "tokens=*" %%A in ('%BATDIR%\GetUserFTA.exe ^| find /i ".pdf,"') DO (
  31.     echo %%A|find /i "AppX"
  32.     IF NOT ERRORLEVEL 1 SET PDF_APPX=1
  33. )
  34.  
  35. IF /i "%~1"=="minimal" (
  36.     IF "%PDF_APPX%"=="0" GOTO complete
  37. )
  38.  
  39. SET /A "RETRIES=1"
  40.  
  41. :set_defaults
  42. set /a "RETRIES=RETRIES+1"
  43. IF %RETRIES% GTR 6 (
  44.     echo Retry limit reached.
  45.     exit /b 1
  46. )
  47.  
  48. "%BATDIR%\SetUserFTA.exe" http IE.HTTP
  49. "%BATDIR%\SetUserFTA.exe" https IE.HTTPS
  50. "%BATDIR%\SetUserFTA.exe" .htm IE.AssocFile.HTM
  51. "%BATDIR%\SetUserFTA.exe" .html IE.AssocFile.HTM
  52.  
  53. if exist "c:\Program Files (x86)\Microsoft Office\Office16\OUTLOOK.EXE" "%BATDIR%\SetUserFTA.exe" mailto Outlook.URL.mailto.15
  54.  
  55. SET ACROBAT_PRO=
  56. SET ACROBAT_READER=
  57. for /f "tokens=1" %%A IN ('reg query HKEY_CLASSES_ROOT\.pdf\OpenWithProgids') DO (
  58.     echo %%A|find /i "Acrobat" >nul
  59.     IF NOT ERRORLEVEL 1 SET "ACROBAT_PRO=%%A"
  60.     echo %%A|find /i "AcroExch" >nul
  61.     IF NOT ERRORLEVEL 1 SET "ACROBAT_READER=%%A"
  62. )
  63. IF NOT "%ACROBAT_PRO%"=="" (
  64.     "%BATDIR%\SetUserFTA.exe" .pdf %ACROBAT_PRO%
  65. ) ELSE (
  66.     IF NOT "%ACROBAT_READER%"=="" "%BATDIR%\SetUserFTA.exe" .pdf %ACROBAT_READER%
  67. )
  68.  
  69. IF EXIST "c:\config\DefaultApps.xml" (
  70.     CALL:set_assoc "c:\config\DefaultApps.xml"
  71. ) ELSE (
  72.     IF EXIST "%BATDIR%\DefaultApps.xml" (
  73.         REM CALL:set_assoc "%BATDIR%\DefaultApps.xml"
  74.     )
  75. )
  76.  
  77. SET PDF_MATCH=0
  78. SET HTM_MATCH=0
  79. SET HTTP_MATCH=0
  80.  
  81. echo.
  82. echo Waiting 30 seconds to see if defaults change...
  83. ping localhost -n 30 >nul
  84.  
  85. IF NOT "%ACROBAT_READER%"=="" (
  86.     for /f "tokens=3" %%B IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice" /v "ProgId"') DO (
  87.         echo "%%B"|find /i "%ACROBAT_READER%"
  88.         IF NOT ERRORLEVEL 1 SET PDF_MATCH=1
  89.     )
  90. ) ELSE (
  91.     SET PDF_MATCH=1
  92. )
  93.  
  94. for /f "tokens=3" %%B IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.htm\UserChoice" /v "ProgId"') DO (
  95.     echo "%%B"|find /i "IE.AssocFile.HTM"
  96.     IF NOT ERRORLEVEL 1 SET HTM_MATCH=1
  97.    
  98.     echo "%%B"|find /i "htmlfile"
  99.     IF NOT ERRORLEVEL 1 SET HTM_MATCH=1
  100. )
  101.  
  102. for /f "tokens=3" %%B IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" /v "ProgId"') DO (
  103.     echo "%%B"|find /i "IE.HTTP"
  104.     IF NOT ERRORLEVEL 1 SET HTTP_MATCH=1
  105. )
  106.  
  107. IF "%PDF_MATCH%"=="0" (
  108.     echo PDF Changed.  Executing again...
  109.     GOTO set_defaults
  110. )
  111. IF "%HTM_MATCH%"=="0" (
  112.     echo HTM Changed.  Executing again...
  113.     GOTO set_defaults
  114. )
  115. IF "%HTTP_MATCH%"=="0" (
  116.     echo HTTP Changed.  Executing again...
  117.     GOTO set_defaults
  118. )
  119.  
  120.  
  121. :complete
  122. IF NOT "%~1"=="" (
  123.     echo %~1>"%USERPROFILE%\%WINVER%_default_apps.txt"
  124. ) ELSE (
  125.     echo done>"%USERPROFILE%\%WINVER%_default_apps.txt"
  126. )
  127. attrib +h "%USERPROFILE%\%WINVER%_default_apps.txt"
  128.  
  129. GOTO END
  130.  
  131. :set_assoc
  132. REM NOTE FOR FUTURE SELF--
  133. REM COULDNT FIGURE OUT HOW TO PROPERLY QUOTE THE BATDIR HERE
  134. REM SO DOING IT WITHOUT QUOTES SINCE I CAN RIGHT NOW (no spaces in path)
  135. for /f "tokens=1 delims=," %%A in ('%BATDIR%\GetUserFTA.exe ^| find /i "AppX"') DO (
  136.     for /f delims^=^"^ tokens^=1-5* %%B in ('type %1 ^| find /i "%%A"') DO (
  137.         echo %%E | find /i "AppX" >nul
  138.         IF ERRORLEVEL 1 (
  139.             echo setting %%C to %%E
  140.             "%BATDIR%\SetUserFTA.exe" %%C %%E
  141.         )
  142.     )
  143. )
  144. exit /b 1
  145.  
  146. :END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement