Skip to content

Instantly share code, notes, and snippets.

@qgustavor
Last active July 15, 2024 01:25
Show Gist options
  • Save qgustavor/5078448 to your computer and use it in GitHub Desktop.
Save qgustavor/5078448 to your computer and use it in GitHub Desktop.
Minecraft Protocol Handler: enable minecraft:// protocol in Windows
@echo off
rem => Minecraft Protocol Handler
rem Enable minecraft:\\ protocol in Windows
rem Usage: minecraft:\\hostname.tld:port
color 1f
set input=%1
if a%input%z == az set input=null
rem It was launched by a link?
if %input:~0,10% == minecraft: (
rem It tries to find Minecraft Launcher:
if exist %~dp0\minecraft.exe (
rem http://www.minecraftwiki.net/wiki/Launcher
rem TODO: test with official launcher
%~dp0\minecraft.exe null null %input:~12%
exit
) else (
if exist %~dp0\skmclauncher.exe (
%~dp0\skmclauncher.exe -launch -address %input:~12%
exit
) else (
echo Minecraft not found.
pause
exit
)
)
)
REM BatchGotAdmin - stackoverflow.com/a/10052222/1850091
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
color a0
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
color 1f
echo === Minecraft Protocol Handler ===
echo It will config Windows to use the protocol minecraft:\\ to open a minecraft server
echo.
if exist minecraft.exe (
set icon=minecraft.exe
goto registry
) else (
if exist skmclauncher.exe (
set icon=skmclauncher.exe
goto registry
) else (
echo First put this file on the same folder as your minecraft launcher.
echo.
pause
exit
)
)
:registry
echo Are you sure?
rem Windows XP don't support choice command:
set /p choice=[Y/N]
if not %choice%==y if not %choice%==Y goto exit
cls
reg add HKCR\minecraft /f
if ERRORLEVEL 1 goto error
reg add HKCR\minecraft /ve /d "URL:Open Minecraft Server" /f
reg add HKCR\minecraft /v "URL Protocol" /d "" /f
reg add HKCR\minecraft\DefaultIcon /f
reg add HKCR\minecraft\DefaultIcon /ve /d "%~dp0%icon%,0" /f
reg add HKCR\minecraft\shell /f
reg add HKCR\minecraft\shell\open /f
reg add HKCR\minecraft\shell\open\command /f
reg add HKCR\minecraft\shell\open\command /ve /d "\"%~f0\" %%1" /f
echo Done!
pause
exit
:error
color cf
echo Try opening it with administrator previlegies.
pause
:exit
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment