You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Windows注册表实现网页调用Notepad.exe仅打开指定name.txt文件

Absolutely, you can make this work! Let's break this into two core parts: configuring Windows to force Notepad to open your specific name.txt every time it launches, and setting up a web button to trigger this action reliably.

1. Configure the Registry for Targeted Notepad Launches

First, let's handle the Registry setup—this covers both web-triggered launches and making Notepad always open name.txt when started normally.

For Web Button Trigger (Custom Protocol)

This creates a unique URL protocol that tells Windows to launch Notepad with your file when called:

  • Open Registry Editor (regedit.exe) as Administrator (you need elevated rights to modify HKEY_CLASSES_ROOT).
  • Navigate to HKEY_CLASSES_ROOT, right-click, and create a new key named something like my-notepad-launcher (pick a unique name to avoid conflicts with existing protocols).
  • Inside this new key:
    • Set the Default string value to "URL:Notepad Launcher for name.txt" (this labels the protocol for Windows).
    • Create a new string value named URL Protocol and leave its data blank (this marks it as a valid protocol handler).
  • Now build the subkey structure: right-click my-notepad-launcher > New > Key, name it shell. Then inside shell, create another key named open, and inside open, create a key named command.
  • In the command key, set the Default value to the full path of Notepad plus your target file. For example:
    "C:\Windows\System32\notepad.exe" "C:\your\file\path\name.txt"
    
    Replace C:\your\file\path\name.txt with the actual absolute path to your file.

For All Notepad Launches (Always Open name.txt)

If you want Notepad to open name.txt every time anyone launches it (double-clicking the exe, start menu, etc.), modify its default command:

  • Navigate to HKEY_CLASSES_ROOT\Applications\notepad.exe\shell\open\command.
  • Double-click the Default value. If it currently has "%1" (which lets Notepad open the clicked file or a blank window), replace it with your file path. For example:
    Original:
    "C:\Windows\System32\notepad.exe" "%1"
    
    Modified:
    "C:\Windows\System32\notepad.exe" "C:\your\file\path\name.txt"
    
    Note: This overrides default behavior—if you ever want to go back, restore the "%1" parameter.
2. Set Up the Web Button

Now that the Registry is configured, you can add a button to your web page that triggers the custom protocol. Here are two simple options:

Option 1: Simple Anchor Tag

<a href="my-notepad-launcher://" target="_blank">Open name.txt in Notepad</a>

Option 2: Button with JavaScript

<button onclick="window.location.href='my-notepad-launcher://'">Open name.txt in Notepad</button>

Key Notes for Web Deployment

  • Most browsers will show a security prompt asking the user to allow the action—this is normal, and users need to click "Allow" to proceed.
  • Make sure the protocol name (my-notepad-launcher) matches exactly what you created in the Registry.
  • If deploying to multiple users, ensure name.txt exists in the same absolute path for everyone, or use a network share path (like \\server\shared\name.txt) that all users can access.

内容的提问来源于stack exchange,提问作者User90

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:32:29