RunTextAsBAT.htm- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312">
- <title>添加到 IE 右键菜单</title>
- <script type="text/javascript">
- var oShell = new ActiveXObject("WScript.Shell");
- var regBase = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\MenuExt\\";
- function addReg() {
- var regTitle, regValue, s1 = stext.value, s2 = salt.value;
- s1 = s1 == "" ? "作为BAT运行" : s1;
- s2 = s2 == "" ? "" : "(&" + s2.substring(0,1).toUpperCase() + ")";
- regTitle = s1 + s2;
- regValue = decodeURI(document.location.href);
- try{
- oShell.RegWrite(regBase + regTitle + "\\", regValue, "REG_SZ");
- oShell.RegWrite(regBase + regTitle + "\\contexts", 52, "REG_DWORD");
- alert("添加成功!");
- } catch(e) {
- alert("添加失败!");
- }
- }
- function delReg() {
- var s1 = sdel.value;
- if (s1.length > 0) {
- s1 = s1.replace(/^(.+)\((\w)\)$/, "$1(&$2)");
- try{
- oShell.RegDelete(regBase + s1 + "\\contexts");
- oShell.RegDelete(regBase + s1 + "\\");
- alert("删除成功!");
- } catch(e) {
- alert("删除失败!");
- }
- }
- }
- function goon(){
- document.getElementById("tips").style.display = "none";
- document.getElementById("doing").style.display = "";
- }
- function mainFunction(s){
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- //var fn = oShell.ExpandEnvironmentStrings("%temp%") + "\\" + "$htmltxt.bat"
- var fn = oShell.SpecialFolders("Desktop") + "\\" + "$htmltxt.bat"
- with(fso.CreateTextFile(fn, true)){
- Write(s);
- Close();
- }
- var cmd = "cmd /c "
- + "@pushd \"" + oShell.SpecialFolders("Desktop") + "\""
- + "&@echo pushd \"%cd%\"&@echo ========= BAT 开始执行 ========="
- + "&call \"" + fn + "\""
- + "&@echo ========= BAT 执行完毕 =========&@pause>nul";
- oShell.Run(cmd);
- }
- if(external.menuArguments) {
- var pDoc = external.menuArguments.document;
- var sSelected = pDoc.selection.createRange().text;
- mainFunction(sSelected);
- }
- </script>
- </head>
- <body onload="goon()">
- <div id="tips" name="tips" style="font:24px/2em Consolas;color:red;">
- ☭<i> === 要想正常使用必须允许脚本和 ActiveX 控件 === </i>❂
- </div>
- <div id="doing" name="doing" style="display:none;text-align:center;font:18px/1.2em 华文楷体,Consolas;">
- <p>
- <b>将选中的文本作为BAT运行</b>
- <table>
- <tr><td>右键中显示名称</td><td><input type="text" id="stext" name=="stext"/></td></tr>
- <tr><td>热键(限一个字母)</td><td><input type="text" id="salt" name=="salt"/></td></tr>
- </table>
- <input type="button" value=" 添 加 " onclick="addReg()" />
- </p>
- <p> </p>
- <p>
- <b>从IE右键删除一个菜单</b>
-
- 显示的名称 <input type="text" id="sdel" name="sdel"/>
-
- <input type="button" value=" 删 除 " onclick="delReg()" />
- </p>
- </div>
- </body>
- </html>
复制代码
|