中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-19 12:07
47,812 topics / 349,917 posts / today 0 new / 48,270 members
DOS批处理 & 脚本技术(批处理室) » Does the `reg requery` query of the registry eat the last character in Chinese paths?
Printable Version  4,619 / 7
Floor1 namejm Posted 2006-08-01 00:51
荣誉版主 Posts 1,737 Credits 5,226 From 成都
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、

[ Last edited by namejm on 2006-8-1 at 15:21 ]
Floor2 3742668 Posted 2006-08-01 13:37
荣誉版主 Posts 718 Credits 2,013
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.
Floor3 zts59 Posted 2006-08-05 13:01
中级用户 Posts 104 Credits 387
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
Floor4 acoreq Posted 2006-08-07 08:17
初级用户 Posts 32 Credits 98 From Shanghai
Good question... Looking forward to the answer
Floor5 HUNRYBECKY Posted 2007-03-18 04:27
银牌会员 Posts 442 Credits 1,179
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
Floor6 Vampire Posted 2007-06-15 18:51
初级用户 Posts 78 Credits 176
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 ]
Floor7 longmarchw Posted 2007-11-20 23:25
初级用户 Posts 10 Credits 21
Return VBS to CMD?
How to return, using file interaction?
Floor8 ooaf Posted 2009-01-08 12:31
中级用户 Posts 162 Credits 313
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
)
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023