如何制作“URL协议"从它自己的目录启动应用程序而不是从 c:\windows\system32 启动? [英] How to make "URL Protocol" to launch application from its own directory instead of launching from c:\windows\system32?

查看:24
本文介绍了如何制作“URL协议"从它自己的目录启动应用程序而不是从 c:\windows\system32 启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用以下脚本在我的系统中注册了一个 URL 协议来启动一个批处理文件showPath.bat".

I have registered a URL protocol in my system using below script to launch a batch file "showPath.bat".

@echo off
reg add HKEY_CLASSES_ROOT\ProtoTest /t REG_SZ /d "My Description" /f
reg add HKEY_CLASSES_ROOT\ProtoTest /v "URL Protocol" /t REG_SZ /d "" /f
reg add HKEY_CLASSES_ROOT\ProtoTest\shell /f
reg add HKEY_CLASSES_ROOT\ProtoTest\shell\open /f
reg add HKEY_CLASSES_ROOT\ProtoTest\shell\open\command /t REG_SZ /d "C:\TestFolder\showPath.bat" /f

pause

showPath.bat"的内容只是为了显示当前的工作目录.即,

Content of "showPath.bat" is just to display the current working directory. ie.,

@echo off
SET var=%cd%
ECHO %var%
pause

如果我直接双击运行批处理文件,我可以正确地看到它的路径.但是,如果我使用上面注册的 URL 协议启动批处理文件.即,从 Chrome 浏览ProtoTest://",批处理文件运行,但显示路径C:\Windows\system32"而不是批处理文件的目录.因此,我相信使用 URL 协议启动的应用程序以 system32 作为工作目录运行.现在如何在使用 URL 协议从浏览器启动时从其自己的目录运行批处理文件 - 而不修改批处理文件本身.只能从我这边更改 URL 协议.

If I run the batch file directly by double clicking it, I can see its path correctly. However if I launch the batch file using the URL protocol registered above. ie, from Chrome, browsing "ProtoTest://", the batch file runs, however display's the path "C:\Windows\system32" instead of the batch file's directory. So, I believe applications launched using URL protocol runs with system32 as working directory. Now How can I get the batch file run from its own directory when launched from browser using URL protocol - without modifying the batch file itself. Only URL protocol possible to be changed from my end.

推荐答案

以下代码对我有用.我将批处理文件放在一个有空格的文件夹中,因此添加了"随着转义字符.然而,它被添加到注册表中,如下图所示,没有转义字符.回答@aschipfl

Below code worked for me. I had my batch file in a folder that had spaces in it, so added "" along with escape char. However it gets added to registry as below in image without escape characters. Answer credit to @aschipfl

@echo off
reg add HKEY_CLASSES_ROOT\ProtoTest2 /t REG_SZ /d "My Description" /f
reg add HKEY_CLASSES_ROOT\ProtoTest2 /v "URL Protocol" /t REG_SZ /d "" /f
reg add HKEY_CLASSES_ROOT\ProtoTest2\shell /f
reg add HKEY_CLASSES_ROOT\ProtoTest2\shell\open /f
reg add HKEY_CLASSES_ROOT\ProtoTest2\shell\open\command /t REG_EXPAND_SZ /d "%ComSpec% /C \"cd /D \"C:\Source\For Ref\URL Protocol\BatchTest\" ^& showPath.bat\"" /f

pause

这篇关于如何制作“URL协议"从它自己的目录启动应用程序而不是从 c:\windows\system32 启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆