Skip to content

Instantly share code, notes, and snippets.

@pratheeshrussell
Last active September 22, 2024 18:41
Show Gist options
  • Select an option

  • Save pratheeshrussell/2f3795b4dc8ff3dc00f868cf8202a1dc to your computer and use it in GitHub Desktop.

Select an option

Save pratheeshrussell/2f3795b4dc8ff3dc00f868cf8202a1dc to your computer and use it in GitHub Desktop.
Run bat file on hyperlink click in Windows
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\folderopen]
"URL Protocol"=""
@="URL:folderopen"
[HKEY_CLASSES_ROOT\folderopen\shell]
[HKEY_CLASSES_ROOT\folderopen\shell\open]
[HKEY_CLASSES_ROOT\folderopen\shell\open\command]
@="\"C:\\shellScripts\\openFolder.bat\" \"%1\""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Folder open test</title>
</head>
<body>
<a href="folderopen:C:\Users\">Open Folder</a>
</body>
</html>
@echo off
setlocal enabledelayedexpansion
rem Step 1: Extract the folder path by removing the "folderopen:" prefix
set "input=%*"
set "folderPath=%input:folderopen:=%"
rem Step 2: URL Decode the folder path
rem Replace %5C with \
set "decodedPath=%folderPath%"
set "decodedPath=!decodedPath:%%5C=\!%"
start "" !decodedPath!
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment