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-06-25 09:33
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] How to use batch processing to analyze the path of favorites in the registry? View 4,169 Replies 19
Original Poster Posted 2006-10-31 09:37 ·  中国 河北 沧州 任丘市 华北油田网络
中级用户
★★
MS-DOS爱好者
Credits 397
Posts 87
Joined 2002-12-15 00:00
23-year member
UID 517
Gender Male
Status Offline
I find that the path of the favorites of many Windows XP users is not the default one, but modified by the users themselves. It is often very troublesome to back up the favorites. Later, I found that the path of the favorites can be found in the registry. The following is the key value I manually exported from a user's registry:


"Favorites"="D:\\!Temporary Folder\\!Internet Temporary Folder\\Favorites"
"Personal"="D:\\!My Documents"
"SendTo"="D:\\!My Documents\\SendTo"


"Favorites"="D:\\!Temporary Folder\\!Internet Temporary Folder\\Favorites"
"Personal"="D:\\!My Documents"
"SendTo"="D:\\!My Documents\\SendTo"
-------------------------------------------------------
I want to use a batch process to achieve the following purposes:
1. First, use the batch process to automatically export the and branches of the user's registry. And save it as the Favorites.reg file.
2. Then, use the batch process to process the Favorites.reg file, obtain the path where the Favorites is located and save it to the %fav% variable for subsequent use.

How can this effect be achieved in the batch process? Please friends give pointers, thank you in advance here!

[ Last edited by sglxy on 2006-11-3 at 08:11 AM ]
Floor 2 Posted 2006-10-31 10:07 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Oh, it's so complicated~ : )

Except for backing up the IE favorites (%HOMEPATH%\Favorites) in the partition where the system is installed,
the important documents used on the desktop and the frequently accessed directories are all just shortcuts pointing to a directory in a non-system partition.
When the system is broken, besides backing up the favorites (RAR compresses the favorites directory, which only takes a minute),
there's nothing else to back up, just do GHOST~ : )

(Except for that favorites, the system partition never stores any things that need to be backed up and take time in the future, which is convenient)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 3 Posted 2006-10-31 10:44 ·  中国 河北 沧州 任丘市 华北油田网络
中级用户
★★
MS-DOS爱好者
Credits 397
Posts 87
Joined 2002-12-15 00:00
23-year member
UID 517
Gender Male
Status Offline
I just want to find the part where "Favorites"="D:\\! Temporary Folder\\! Internet Temporary Folder\\Favorites" and change it to D:\! Temporary Folder\! Internet Temporary Folder\Favorites and save it to the %fav% variable.
Floor 4 Posted 2006-10-31 12:22 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline


@ECHO OFF&SETLOCAL ENABLEDELAYEDEXPANSION
for /f "tokens=1,2,*" %%i in ('REG QUERY "HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\EXPLORER\SHELL FOLDERS" ^| FIND /I "FAVORITES"') DO (
SET Fav_IN_SHELL_FAV=%%k
ECHO The value of Favorites under the SHELL FOLDERS subkey is:
ECHO !Fav_IN_SHELL_FAV!)
echo
for /f "tokens=1,2,*" %%i in ('REG QUERY "HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\EXPLORER\USER SHELL FOLDERS" ^| FIND /I "FAVORITES"') DO (
SET Fav_USER_SHELL_FAV=%%k
ECHO The value of Favorites under the USER SHELL FOLDERS subkey is:
ECHO !Fav_USER_SHELL_FAV!)
PAUSE

Floor 5 Posted 2006-10-31 12:37 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
```
@echo off
for /f "tokens=2,*" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Favorites"') do (
set Fav=%%j
)
echo The current favorites are located at %Fav%
pause
```

[ Last edited by fastslz on 2006-10-31 at 12:52 PM ]
第一高手 第二高手

Floor 6 Posted 2006-10-31 19:09 ·  中国 河北 沧州 任丘市 华北油田网络
中级用户
★★
MS-DOS爱好者
Credits 397
Posts 87
Joined 2002-12-15 00:00
23-year member
UID 517
Gender Male
Status Offline
Both friends' methods are very concise, but the value obtained is not the D:\!Temporary Folder\!Internet Temporary Folder\Favorites I hoped for. Instead, it seems like the short path: The current favorite is located in D:\Internet Temporary Document?
Floor 7 Posted 2006-10-31 20:27 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Actually, you can directly use the mouse to cut to the subsequent disk. After cutting, make a backup and then it will always recognize the subsequent disk.
Floor 8 Posted 2006-10-31 21:05 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Seems like the short path kind? I haven't tested the Chinese long file name yet~
第一高手 第二高手

Floor 9 Posted 2006-10-31 21:18 ·  中国 河北 沧州
中级用户
★★
MS-DOS爱好者
Credits 397
Posts 87
Joined 2002-12-15 00:00
23-year member
UID 517
Gender Male
Status Offline
Originally posted by NaturalJ0 at 2006-10-31 08:27 PM:
Actually, you can directly use the mouse to cut to the subsequent drive. After cutting, make a backup and then it will always recognize the subsequent drive.





Thanks to NaturalJ0 for the enthusiastic answer. The reason why a batch processing method is needed for automatic analysis is to make it one of the modules of a certain batch processing, which can greatly reduce the labor intensity of the operator in system maintenance. Using the mouse would lose the meaning.

In addition, inspired by the friends on floors 4 and 5, I rewrote my work as follows. Please friends give your comments:
@echo off
reg export "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" fav.reg
for /f "tokens=2 delims==" %%b in ('find /i "Favorites" fav.reg') do set fav=%%b
set fav=%fav:\\=\%
set fav=%fav:"=%
echo The favorite folder of this computer is located at %fav%>收藏夹.txt
del fav.reg
pause>nul


But after the execution of this batch script ends, there is always a prompt "Operation completed successfully". How to remove it?

[ Last edited by sglxy on 2006-10-31 at 09:26 PM ]
Floor 10 Posted 2006-10-31 22:04 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
```
@echo off
REG EXPORT "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" a.reg /nt4>nul
for /f "tokens=2 delims==" %%a in ('find "Favorites" a.reg') do set fav=%%~a
echo The favorite folder is located at %fav%
```
Floor 11 Posted 2006-10-31 22:36 ·  中国 河北 沧州
中级用户
★★
MS-DOS爱好者
Credits 397
Posts 87
Joined 2002-12-15 00:00
23-year member
UID 517
Gender Male
Status Offline
Thanks to the moderator qwe1234567, I understand. Originally, this prompt was generated by the reg command. I initially thought it was generated by del fav.reg.
Floor 12 Posted 2006-11-01 00:23 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  Unexpectedly, reg export has a hidden parameter, heh, learned it.
Floor 13 Posted 2006-11-01 00:51 ·  中国 河北 沧州 任丘市 华北油田网络
中级用户
★★
MS-DOS爱好者
Credits 397
Posts 87
Joined 2002-12-15 00:00
23-year member
UID 517
Gender Male
Status Offline
May I ask the super moderator, what does the "/nt4" parameter in the sentence REG EXPORT "HKCU\Software\…… mean?

In addition, there is a sentence in your post: set fav=%%~a. I know it's assignment. But why is "%%a" written as "%%~a", what is its meaning? Please give me some guidance.

[ Last edited by sglxy on 2006-11-1 at 12:54 AM ]
Floor 14 Posted 2006-11-01 01:39 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

The "/nt4" parameter specifies the registry version information indicated in the exported registry file, which is "REGEDIT4". Without the "/nt4" parameter, the version may be "Windows Registry Editor Version 5.00".

"%%~a" is an expansion of the "%%a" variable, and its function is to remove the quotes outside "%%a".
Floor 15 Posted 2006-11-01 01:41 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Deputy version answers: %%~a means to remove any quotes before and after the string.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Forum Jump: