DOS mode in the registry to operate the code

Time:2021-4-13

Because the registry editor Regedit.exe In fact, it is a two habitat program, which can run under DOS or windows 95 / 98. Many users may already know how to use regedit in windows, so to master the registry programming in DOS mode, we must first understand how to use the registry editor in DOS.
Type the regedit command at the DOS prompt and a help screen will appear. This screen gives its command line parameters and how to use them.
Syntax: regedit / / L: system / / R: user] filename1
 Regedit [/L:system] [/R:user] /C filename2
 Regedit [/L:system] [/R:user] /E filename3 [regpath]
Among them:
/ L: system specification system.dat The location of the document.
/ L: user specified user.dat The location of the document.
Filename1 specifies the file name to import into the registry database.
/ C filename2 specifies the file name that forms the registry database.
/ E filename3 specifies the file name of the exported registry file.
Regpath is the default key to export all files
Here are some examples regedit.exe How to use DOS.
[example 1] export the system registry database registry to the reg1.reg file.
  regedit /E reg1.reg
[example 2] reg1.reg is in the registry database of the system.
  regedit /C reg1.reg
[example 3] reg.dat It is introduced into the system registry database (part).
  regedit reg.dat
[example 4] export Cjh started keywords to the registry database and name them as cjh.reg .  
 regedit /E cjh.reg cjh
[example 5] the specified system / dat is stored in D: Pwin user.dat Store in E: Pwin, and reg.dat The data file forms a new registry database.
  regedit /L:\PWIN /R:E:\PWIN /C reg.dat

With the above knowledge, combined with the “shortcut” of registry programming, we can program the registry in DOS mode.

Let’s take the example of changing the default opening mode of “*. TXT” file – “NOTEPAD” to “WordPad”. First, export “HKEY” at the MS-DOS prompt_ CLASSES_ To execute the command, you need to use the “root / txtfile” subkey

  regedit /E txt.reg HKEY_CLASSES_ROOT\txtfile

Then open it with edit editor under DOS txt.reg File to edit: all the “C: \ \ windows”\\ NOTEPAD.EXE ”Change all to “C: \ \ windows”\\ WRITE.EXE ”To save the disk, exit edit, and then execute the command from the command line

  regedit txt.reg

And it’s done.
Of course, strictly speaking, this is not programming. If we have to program, we can write the above process into a batch of processing files chang.bat :

@echo off
path=c:\windows;c:\windows\command;c:\dos
cls
Echo exporting registry
  regedit /E txt.reg HKEY_CLASSES_ROOT\txtfile
echo.
Echo registry export finished! Press any key to edit registry
echo.
pause
edit txt.reg
Echo is importing the modified registry
regedit txt.reg
Echo congratulations! Successfully modified the registry in MS-DOS mode!
pause
cls
@echo on

To give full play to the powerful function of the edit editor, we can modify, delete or add any subkey to the registry at will on the premise of following the format of the exported registry file. If you feel that this is not programmed enough, you can give full play to the advantages of various programming languages in DOS environment, coupled with the interactive interface, and truly program this process, which should not be inferior to the effect of using API functions in Windows state. Interested friends can try. If you have any questions about this, please contact me( [email protected] )。