无需批处理:通过注册表配置特定扩展名文件用默认浏览器打开带路径本地URL
Got it, let's cut out that batch file middleman and set up your .mylog files to open directly in the browser with the file path in the URL. Here's exactly how to do it step by step:
Step 1: Link .mylog to a custom file type
Open the Registry Editor by typingregedit.exein the Start Menu or Run dialog. Navigate toHKEY_CLASSES_ROOT\.mylog.
Set the default value (right-click → Modify) to a unique identifier likeMyLogFileHandler—this is just a name to tie the file extension to our custom command.Step 2: Create the "Open" command structure
Now we need to build the command that runs when you double-click a .mylog file. Navigate toHKEY_CLASSES_ROOT\MyLogFileHandler(create this key if it doesn't exist: right-clickHKEY_CLASSES_ROOT→ New → Key, name itMyLogFileHandler).
Under that, create these subkeys in order:- Right-click
MyLogFileHandler→ New → Key, name itshell - Right-click
shell→ New → Key, name itopen - Right-click
open→ New → Key, name itcommand
- Right-click
Step 3: Set the command to launch the browser
Select thecommandkey, then double-click the default value in the right pane. Paste this command:cmd /c start "" "http://localhost:3210/?myFile=%1"Let's break this down:
cmd /c: Runs the following command and then closes the command prompt window automatically.start "": The empty quotes are critical here—they act as the window title for thestartcommand, which prevents errors when the file path contains spaces.%1: This placeholder gets replaced with the full path of the .mylog file (including quotes if the path has spaces) when you double-click it.
Step 4: Test it out
Close the Registry Editor, then double-click any .mylog file. Your default browser should open straight tohttp://localhost:3210/?myFile=C:\your\file\path.mylog—no batch file involved!
Optional: Use a specific browser instead of default
If you want to force a particular browser (like Chrome or Edge) instead of the system default, replace the command with the full path to the browser executable. For example, for Chrome:
"C:\Program Files\Google\Chrome\Application\chrome.exe" "http://localhost:3210/?myFile=%1"
Quick Note
Always back up your registry before making changes (File → Export in Registry Editor) just to be safe—though these steps are straightforward and low-risk when done correctly.
内容的提问来源于stack exchange,提问作者Amir

