头两天写了一个简单的查看开机自启动程序路径的代码,姑且不论查询得是否全面,在测试的过程中发现了一个十分头痛的问题:
如果自启动程序的路径中含有N个中文字符的话(在注册表中的字符类型为REG_SZ,其他类型的字符暂未测试),那么,这个路径的最后N个字符(一个中文字符占用两个字符位)将被忽略掉,可能和中文的内码是双字节有关,具体的原因我也说不清楚。比如,在HKEY_Local_Machine\Software\Microsoft\Windows\CurrentVersion\Run下建立REG_SZ字符串test,值为 c:\program files\测试\test.exe ,那么,执行的代码之后,test所在行显示为 c:\program files\测试\test.e ;如果上述值为 c:\program files\测试\再次测试.exe 的话,结果将显示 c:\program files\测试\再次测 。
请问,这个问题该如何解决?
1、
@echo off
setlocal enabledelayedexpansion
echo.
echo 开机自启动的程序有:
echo.
for /f "skip=4 tokens=1* delims=:" %%i in ('reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run') do (
set str=%%i
set var=%%j
set "var=!var:"=!"
if not "!var:~-1!"=="=" echo !str:~-1!:!var!
)
pause>nul
Last edited by namejm on 2006-8-1 at 15:21 ]
A couple of days ago, I wrote a simple piece of code to view the paths of programs that start automatically at boot . Regardless of whether the query is comprehensive or not, during testing, I encountered a very headache-inducing problem:
If the path of a program that starts automatically at boot contains N Chinese characters (the character type in the registry is REG_SZ, and other types of characters haven't been tested yet), then the last N characters of this path (one Chinese character occupies two character positions) will be ignored. It might be related to the fact that the internal code of Chinese is double-byte, and I can't specifically explain the reason. For example, create a REG_SZ string test under HKEY_Local_Machine\Software\Microsoft\Windows\CurrentVersion\Run with the value c:\program files\测试\test.exe. Then, after executing the code in , the line where test is located shows c:\program files\测试\test.e; if the above value is c:\program files\测试\再次测试.exe, the result will show c:\program files\测试\再次测.
How should this problem be solved?
1、
@echo off
setlocal enabledelayedexpansion
echo.
echo The programs that start automatically at boot are:
echo.
for /f "skip=4 tokens=1* delims=:" %%i in ('reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run') do (
set str=%%i
set var=%%j
set "var=!var:"=!"
if not "!var:~-1!"=="=" echo !str:~-1!:!var!
)
pause>nul
Last edited by namejm on 2006-8-1 at 15:21 ]