China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-16 06:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Does the `reg requery` query of the registry eat the last character in Chinese paths? View 4,262 Replies 7
Original Poster Posted 2006-08-01 00:51 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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 ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 2 Posted 2006-08-01 13:37 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Looking at the method of reading the registry at startup and processing the results by oneself is a bit thankless.

If it's the XP system, it is recommended to use WMIC to achieve it best: wmc startup, if you find the output result difficult to view, you can use wmic startup list brief, if you want to filter the output result, you can use wmic startup where filter conditions get output items.

One line of command can read multiple items of the registry, and there is no need to lay out by oneself, and no error handling is needed.

Regarding your code, I have doubts about the usage of tokens=1*. In addition, personally, I think the method of delims=: is not very good. The error in your result may still be due to the incompatibility of the character encoding scheme in the output of for and reg commands. You can redirect the result of the reg command to a text file, and then open it with a hex editor to have a look.
Floor 3 Posted 2006-08-05 13:01 ·  中国 广东 东莞 电信
中级用户
★★
Credits 387
Posts 104
Joined 2004-11-19 00:00
21-year member
UID 33813
Gender Male
Status Offline
Create a project with a startup path containing Chinese characters.

reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run>aa.txt

Tried it, and indeed characters are being eaten.

Result:


! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
wallpaper REG_SZ c:\windows\测试\壁纸自?
IMSCMig REG_SZ C:\PROGRA~1\COMMON~1\MICROS~1\IME\IMSC40A\IMSCMIG.EXE /Preload
Floor 4 Posted 2006-08-07 08:17
初级用户
傻傻分不清楚...
Credits 98
Posts 32
Joined 2006-07-01 14:29
20-year member
UID 57838
From Shanghai
Status Offline
Good question... Looking forward to the answer
Floor 5 Posted 2007-03-18 04:27 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
The problem has been solved, and there are multiple methods:
One is to use the REG of 2003 to replace the REG of WINXP:
http://www.cn-dos.net/forum/viewthread.php?tid=27279&page=1&sid=Bi8yqD#pid182590 The post on the 11th floor
The second is that you can use VBS to return to CMD. I think this method is relatively good.
Set WshShell = Wscript.CreateObject("Wscript.Shell")
tt=WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Start Menu") '' Read from value "Val"
Wscript.echo tt
Floor 6 Posted 2007-06-15 18:51 ·  中国 广东 广州 鹏博士宽带
初级用户
★★
Credits 176
Posts 78
Joined 2007-04-15 10:53
19-year member
UID 85268
Gender Male
Status Offline
I also have this situation. When querying, it shows normally, but when outputting to a file, it cuts corners.

D:\desktop>reg query "hkcu\software\microsoft\windows\currentversion\explorer\user shell folders" /v startup

! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\software\microsoft\windows\currentversion\explorer\user shell folders
startup REG_EXPAND_SZ %USERPROFILE%\「开始」菜单\程序\启动
---------------------------------------------------------------------------------------------------------------
D:\desktop>reg query "hkcu\software\microsoft\windows\currentversion\explorer\user shell folders" /v startup >>test.txt
-----------------
Content of test.txt
-----------------

! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\software\microsoft\windows\currentversion\explorer\user shell folders
startup REG_EXPAND_SZ %USERPROFILE%\「开始」菜单

Because this is a batch script for XP users, it's unrealistic to ask them to switch to 2003REG. I used the VBS method from floor 5, thanks.

[ Last edited by Vampire on 2007-6-15 at 06:59 PM ]
Floor 7 Posted 2007-11-20 23:25 ·  中国 浙江 杭州 电信
初级用户
Credits 21
Posts 10
Joined 2007-11-20 22:37
18-year member
UID 103273
Gender Male
Status Offline
Return VBS to CMD?
How to return, using file interaction?
Floor 8 Posted 2009-01-08 12:31 ·  中国 北京 联通
中级用户
★★
Credits 313
Posts 162
Joined 2007-04-02 06:45
19-year member
UID 83693
Gender Male
Status Offline
Transfer from the very batch tireless:

@echo off
pause
for /f "skip=4 tokens=3 delims=此处为Tab键" %%a in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run') do (
(echo %%a
)
Forum Jump: