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-08-01 15:48
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Great expert-level question, key words: batch processing, registry. Looking forward to the moderator! View 1,475 Replies 12
Original Poster Posted 2006-04-04 16:06 ·  中国 湖南 长沙 岳麓区 电信
新手上路
Credits 8
Posts 2
Joined 2006-04-04 15:27
20-year member
UID 53316
Gender Male
Status Offline
Dear all, this is my first time here, and I have a very deep question.

Implementation effect:
Every time the system restarts, it will call the backed-up registry. All registry modifications made after the system starts will be replaced by the backed-up registry after the system restarts.

It is required to be implementable in win98, win2K, winxp, win2k3.

My own idea is:
Use batch processing
Delete the entire registry
Call the backed-up registry

But my ability is limited, and I can't implement it. Looking forward to the appearance of experts.
Floor 2 Posted 2006-04-04 17:43 ·  中国 北京 朝阳区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
OH ,MY GOD.....I don't know if the original poster has a fever or I do.........Delete the registry?????Say another "OH ,MY GOD!"
Floor 3 Posted 2006-04-04 17:54 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Why back up and restore the entire registry? If it were me, I would selectively back up...

But according to your train of thought, I can provide you with methods:

Command to back up the registry: regedit /e c:\bak.reg

Command to import the registry: regedit /s c:\bak.reg

Although the regedit command can run under 98 and XP, for XP, involving permissions and other situations, maybe it won't necessarily restore successfully (this is just my opinion.)

If it's 98, it's suggested that you just back up System.dat and User.dat, and then restore when you want to.

After all, restoring the registry every time you start up takes some time.

ps: Personally, I think this problem isn't even what can be considered a big shot-level problem.
Floor 4 Posted 2006-04-04 18:08 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
XP can also back up the registry by directly backing up the registry file, but the premise is that XP is not in the running state. And the same requirement applies when restoring the backed-up registry. Personally, I think this is really not a problem for an expert-level person.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 5 Posted 2006-04-05 00:06 ·  中国 湖北 武汉 电信
初级用户
★★
Credits 168
Posts 85
Joined 2005-08-26 00:19
20-year member
UID 41941
Gender Male
Status Offline
Originally posted by 3742668 at 2006-4-4 17:54:
Command to back up the registry: regedit /e c:\bak.reg
Command to import the registry: regedit /s c:\bak.reg


I also saw others mention that a regedit -m opens two regedit.exe

May I ask how these parameters of regedit are obtained?
I searched on the Microsoft official website for a long time but couldn't find a comprehensive introduction to these parameters~~
Floor 6 Posted 2006-04-05 00:23 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
DOS下regedit /?
I used to specifically look at it when I was using 98, so I still have some impression. But in the command line of XP, running regedit /? can't be seen, but regedit /s and regedit /e can still be executed.
Floor 7 Posted 2006-04-05 08:37 ·  中国 湖南 长沙 岳麓区 电信
新手上路
Credits 8
Posts 2
Joined 2006-04-04 15:27
20-year member
UID 53316
Gender Male
Status Offline
Maybe I didn't describe it clearly.
What I mean is that after installing the system and application software, the system is handed over to the user for use, so that the user cannot add information to the registry by installing application programs. Even if the software that needs to add information to the registry is installed, after restarting, it will not run normally because the registry is restored... (except for green software)

According to the opinion of floor 3, can we execute a batch command in the group policy before the system runs:
regedit /s e:\bak.reg
Note: bak.reg is the registry exported after the system is installed. In this way, every time the system is restarted, the one used is bak.reg.
But I'm thinking about such a problem. If the user adds new information to the registry and then imports bak.reg, will it cause system errors, (whether the newly added information is cleared)
Floor 8 Posted 2006-04-05 10:41 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
First of all, if you change settings in the registry, importing bak.reg will modify it to the values in bak.reg. But if a key is added, importing bak.reg will not delete the already established values (this is why I said it's best to back up and restore system.dat and user.dat under Windows 98). Under Windows 98, we can restore system.dat and user.dat in autoexec.bat or win.bat, etc., to achieve the purpose of truly restoring the registry. But this method is not practical under XP. Moreover, if the software changes and the registry is not properly configured accordingly, it may lead to inexplicable situations such as the software not working properly. So basically, don't do this thankless thing. As for achieving the purpose you want, in the XP environment, you only need to create a user with a relatively low privilege, such as in the users group. If you really want to modify the registry yourself, it's not impossible. You can first export the registry each time, then use a batch script to extract each line starting with "[" and then insert a minus sign "-" before the second valid character in the extracted file. For example, if the original content is:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
Just change it to
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
Then import the modified reg file, which will delete all subkeys (of course, you can also directly record the names of the subkeys under each root key and then directly delete these subkeys in the batch script).
After deleting the key, import bak.reg.
It is still not recommended to use this most cumbersome, least efficient, and most dangerous method to maintain security.
Floor 9 Posted 2006-04-05 13:12 ·  中国 湖北 武汉 电信
初级用户
★★
Credits 168
Posts 85
Joined 2005-08-26 00:19
20-year member
UID 41941
Gender Male
Status Offline
Study it again~~
Floor 10 Posted 2006-04-05 18:33 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Installing a hard drive protection card is quite simple. It can also meet the owner's needs.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 11 Posted 2006-05-11 13:26 ·  IANA 局域网IP(Private-Use)
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
regedit /c seems to be able to use .reg to rebuild the registry
Floor 12 Posted 2006-05-11 19:00 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re shgengen:

According to the requirement description you provided on floor 7, it feels somewhat similar to the maintenance of an internet café system. In such cases, restoring the registry is usually not the method adopted to restrict the use of non-green applications. In addition to the disadvantages of high complexity, poor compatibility, and high risk, this method also has the defect of easily generating redundant files. Therefore, the following solutions are usually adopted for such requirements.

1. The hard disk protection card or hard disk restoration software mentioned by Brother Climbing on floor 10 can write-protect the system disk, so that it can automatically restore to the initial state after each boot, and green software can be installed on the non-system disk without being affected.

2. Use a self-starting image restoration software similar to One-click Restore to back up the system disk in advance, and restore it after the system disk changes significantly. Because the restoration takes much longer than solution 1, the restoration cycle also needs to be appropriately extended, for example, restoring at the first boot every day instead of at every boot.

In addition, there are ready-made registry restoration tools under Win9x, scanreg.exe/scanregw.exe. Writing scanreg /restore into autoexec.bat or writing scanregw /restore into the run startup item in the registry can make it automatically restore the registry at startup.

[ Last edited by willsort on 2006-5-11 at 19:36 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 13 Posted 2006-05-11 23:07 ·  中国 上海 杨浦区 电信
高级用户
★★
Credits 653
Posts 252
Joined 2006-04-16 19:48
20-year member
UID 53939
Status Offline
The import and export functions of regedit involve conversion of data representation (binary data <-> plain text data). In a typical configuration, the time-consuming conversion for the entire registry each time it starts is too great. It's not as cost-effective as restoring with disk images, unless your disk IO is extremely slow but CPU is extremely fast (one is compute - intensive and the other is IO - intensive).

If you just want to fully restore the registry, overwriting the file is the simplest and most efficient way. But for NT Kernel OS, it is more troublesome to perform the overwrite before the system starts (the registry file is loaded and locked). It seems there are two methods.

**Method 1**
1. Power - on self - test
2. Load boot manager from MBR, find it's the odd - numbered start
3. Load an independent DOS system
4. [Optional] Load NTFS file system driver
5. Overwrite the system file with the backed - up registry file
6. Restart the machine, load boot manager again, find it's the even - numbered start
7. Load NT/2k/XP/2k3

Obviously, this scheme must have a boot manager that supports judging some non - volatile flag bits.

**Method 2**
1. Power - on self - test
2. Boot an independent DOS system from MBR
3. [Optional] Load NTFS file system driver
4. Overwrite the system file with the backed - up registry file
5. Load GRUB4DOS and use it to load NT series OS

Just don't know if GRUB4DOS can directly load NT Kernel under DOS. Even if it can, it seems that at least about 1M of memory will be consumed.
Forum Jump: