标题: [注册表类] [已解决]批处理怎样获取当前路径并更改路径格式后写入注册表? [打印本页]
作者: meetyoucrash 时间: 2010-7-13 16:17 标题: [已解决]批处理怎样获取当前路径并更改路径格式后写入注册表?
- @echo off
- tasklist|find /i "FreeGate.exe" || goto tor
- reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /d file:^/^/"%cd%"/**GFW-FreeGate.pac /f
- echo.
- echo 成功设置为自由门专用PAC代理
- PAUSE
复制代码
由于浏览器的关系,不同浏览器对地址的识别也不一样,我这里就需要获取file:///x:/x/x/x.xx这种格式的当前路径并写入注册表。猜想获取路径后替换反斜杠为正斜杠应该可以,但具体不知道怎么做。
作者: meetyoucrash 时间: 2010-7-13 17:06
换了个非中文路径,批处理运行后工作正常。不知道有没有什么方法将完整路径中包含的中文路径转换为可识别的格式?看到有个是用C#来转换的,我想要批处转换
[ 本帖最后由 meetyoucrash 于 2010-7-13 17:35 编辑 ]
作者: hfg1977 时间: 2010-7-13 18:39
说了半天够乱的,
简单一句话: 把%CD%中的 "\" 替换为 "/"- set "filepath=%cd%"
- set "filepath=%filepath:\=/%"
- reg add "HKEY_CURRENT_USER\00" /v AutoConfigURL /d file:^/^/"%filepath%"/FuckGFW-FreeGate.pac /f
复制代码
测试通过
作者: meetyoucrash 时间: 2010-7-13 18:59
现在最大的麻烦是出现中文路径时,直接将带中文路径的值写入注册表后浏览器不识别,浏览器只识别类似%BE%DA类似格式的地址值,不识别中文。感谢楼上的大哥指教替换
作者: hfg1977 时间: 2010-7-13 20:30
下面代码把路径中的所有字符替换成 %x 形式,包括英文.
想还原英文,就再根据ASCII码表替换, 你自己写吧.
不知道VBS又什么好方法.- @echo off
- setlocal enabledelayedexpansion&cls
- path=%path%;%~dp0.\网络;%~dp0.\command\第三方命令行程序;%~dp0.\command;%~dp0.\源码;%~dp0.\系统备份
- ::==============================================================
- :start
-
- set "filepath=%cd%"
- ::=======生成 HEX ASCII值=========
- echo %filepath%>1.txt
- for %%a in (1.txt) do set size=%%~za
- if "%size%"=="0" goto end
- fsutil file createnew 01.txt %size% >nul
- for /f "skip=1 tokens=2" %%a in ('fc /b 1.txt 01.txt') do (
- if "%%a"=="0D" goto next
- set "pathHEX=!pathHEX!%%%%a
- )
- :next
-
- ::把%5C也就是"\"替换 为"/"
- set "pathHEX=!pathHEX:%%5C=/!"
- echo %pathHEX%
-
- reg add "HKEY_CURRENT_USER\00" /v AutoConfigURL /d file:^/^/"%pathHEX%"/FuckGFW-FreeGate.pac /f
-
- ::==============================================================
复制代码
作者: hfg1977 时间: 2010-7-13 20:39
IE 可以打开 file:///G:/DOS/command/第三方命令行程序 这样的地址
下面格式的地址打不开
file:///G:/DOS/command/%B5%DA%C8%FD%B7%BD%C3%FC%C1%EE%D0%D0%B3%CC%D0%F2
[ 本帖最后由 hfg1977 于 2010-7-13 20:42 编辑 ]
作者: meetyoucrash 时间: 2010-7-13 21:12
注册表里要写入这样的值file:///G:/DOS/command/%B5%DA%C8%FD%B7%BD%C3%FC%C1%EE%D0%D0%B3%CC%D0%F2
浏览器会自动转换回中文,但如果写入带中文的目录名,浏览器则不能识别
上面的方法试过了,可还是不行。上面那个把整个当前目录的地址全部转换了,我从注册表读取出来的值是只转换中文部分的
格式不对
网络相关/代理
转换成这个格式是:
%E7%BD%91%E7%BB%9C%E7%9B%B8%E5%85%B3/%E4%BB%A3%E7%90%86
如果在浏览器中输入这段地址会自动翻译为中文地址
在论坛找到这个代码,转换的完全正确,但是它直接忽略了斜杠,输出的值还是不能直接使用,麻烦你能不能帮忙改一下
::EC_URI.JS::编码URI
@echo off
set JSF="%TMP%\EC_URI.JS"
echo=WScript.echo(encodeURIComponent(WScript.Arguments(0)));>%JSF%
set/pSTR=请输入URI地址(或普通字串):
cscript //nologo %JSF% "%STR%"
pause
[ 本帖最后由 meetyoucrash 于 2010-7-13 22:22 编辑 ]
作者: hfg1977 时间: 2010-7-14 00:09
完成代码,试验通过 ^-^
主程序:- @echo off
- setlocal enabledelayedexpansion&cls
- path=%path%;%~dp0.\网络;%~dp0.\command\第三方命令行程序;%~dp0.\command;%~dp0.\源码;%~dp0.\系统备份
- ::==============================================================
- :start
-
- call ASCII_Hex.bat %cd%
- set /p strHEX=<strHEX.txt
- echo %strHEX%
- set "strHEX=%strHEX:\=/%"
- reg add "HKEY_CURRENT_USER\00" /v AutoConfigURL /d file:^/^/^/"%strHEX%"/FuckGFW-FreeGate.pac /f
-
- ::==============================================================
- :end
- ENDLOCAL&echo 按任意键退出&pause>nul
- mode con cols=80 lines=25&color 07&graftabl 936>nul
- ::mode con cols=80 lines=30&color 07&graftabl 437>nul
- goto:eof
复制代码
函数程序:- ::BAT_NAME: ASCII_Hex.bat
- ::格式: call ASCII_Hex.bat %*
- ::返回值: strHEX.txt
- ::调用: call ASCII_Hex.bat %*
- :: set /p strHEX=<strHEX.txt
- :: echo %strHEX%
- @echo off
- setlocal enabledelayedexpansion&cls
- path=%path%;%~dp0.\网络;%~dp0.\command\第三方命令行程序;%~dp0.\command;%~dp0.\源码;%~dp0.\系统备份
- ::==============================================================
- set "_20= " &set "_38=8" &set "_50=P" &set "_68=h"
- set "_21=" &set "_39=9" &set "_51=Q" &set "_69=i"
- set "_22=" &set "_3A=:" &set "_52=R" &set "_6A=j"
- set "_23=#" &set "_3B=;" &set "_53=S" &set "_6B=k"
- set "_24=$" &set "_3C=<" &set "_54=T" &set "_6C=l"
- set "_25=%%" &set "_3D==" &set "_55=U" &set "_6D=m"
- set "_26=&" &set "_3E=>" &set "_56=V" &set "_6E=n"
- set "_27='" &set "_3F=?" &set "_57=W" &set "_6F=o"
- set "_28=(" &set "_40=@" &set "_58=X" &set "_70=p"
- set "_29=)" &set "_41=A" &set "_59=Y" &set "_71=q"
- set "_2A=*" &set "_42=B" &set "_5A=Z" &set "_72=r"
- set "_2B=+" &set "_43=C" &set "_5B=[" &set "_73=s"
- set "_2C=," &set "_44=D" &set "_5C=\" &set "_74=t"
- set "_2D=-" &set "_45=E" &set "_5D=]" &set "_75=u"
- set "_2E=." &set "_46=F" &set "_5E=^" &set "_76=v"
- set "_2F=/" &set "_47=G" &set "_5F=_" &set "_77=w"
- set "_30=0" &set "_48=H" &set "_60=`" &set "_78=x"
- set "_31=1" &set "_49=I" &set "_61=a" &set "_79=y"
- set "_32=2" &set "_4A=J" &set "_62=b" &set "_7A=z"
- set "_33=3" &set "_4B=K" &set "_63=c" &set "_7B={"
- set "_34=4" &set "_4C=L" &set "_64=d" &set "_7C=|"
- set "_35=5" &set "_4D=M" &set "_65=e" &set "_7D=}"
- set "_36=6" &set "_4E=N" &set "_66=f" &set "_7E=~"
- set "_37=7" &set "_4F=O" &set "_67=g" &set "_7F="
- ::==============================================================
- if not "%*"=="" (set "str=%*") else (set "str=G:\DOS\command\第三方命令行程序")
- call:strHEX %str%
- exit /b
- ::==============================================================
- :strHEX
- ::=======生成 HEX ASCII值=========
- echo %str%>1.txt
- for %%a in (1.txt) do set size=%%~za
- if "%size%"=="0" goto end
- fsutil file createnew 01.txt %size% >nul
- for /f "skip=1 tokens=2" %%a in ('fc /b 1.txt 01.txt') do (
- if "%%a"=="0D" goto next
- ::echo "!_%%a!"=="%%a"
- if not "!_%%a!"=="" (set "strHEX=!strHEX!!_%%a!") else (set "strHEX=!strHEX!%%%%a")
- )
- :next
- echo %strHEX%>strHEX.txt
- del 1.txt 01.txt
- goto:eof
- ::==============================================================
复制代码
[ 本帖最后由 hfg1977 于 2010-7-14 05:40 编辑 ]
作者: meetyoucrash 时间: 2010-7-14 01:03
直接定义了一个 ASCII 表,太感谢了,只是有很多语句我都不会用,要学习好一段时间呢。
再次致谢……
作者: 34205 时间: 2015-1-23 16:01
学习了,各种手法
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |