Programming the registry under DOS mode
Can you program the registry under DOS mode too? Yes. When your Windows 95/98 cannot boot into the graphical interface because of a registry problem, at that point you can only operate on the registry under DOS. This is because the registry editor Regedit.exe is actually an amphibious program: it can run both under DOS and under Windows 95/98. Many users may already know how to use Regedit under Windows, so to master registry programming under DOS mode, you first need to understand how to use the registry editor under DOS.
At the DOS prompt, type the Regedit command and a help screen will appear. This screen gives its command-line parameters and how to use them.
Syntax: Regedit filename1
Regedit /C filename2
Regedit /E filename3
Where:
/L:system specifies the location of the system.dat file.
/L:user specifies the location of the user.dat file.
filename1 specifies the filename to import into the registry database.
/C filename2 specifies the filename used to create the registry database.
/E filename3 specifies the filename of the exported registry file.
regpath specifies the starting keyword for exporting the registry file (default is all keywords)
Now here are a few examples to explain how to use regedit.exe under DOS.
【Example 1】 Export the system registry database registry to the reg1.reg file.
regedit /E reg1.reg
【Example 2】 Use reg1.reg to create the system registry database registry (entire).
regedit /C reg1.reg
【Example 3】 Import reg.dat into the system registry database (partial).
regedit reg.dat
【Example 4】 Export the keywords starting with CJH from the registry database and name it cjh.reg.
regedit /E cjh.reg cjh
【Example 5】 Specify system/dat as stored in D:\PWIN and user.dat as stored in E:\PWIN, and use the reg.dat data file to create a new registry database registry.
regedit /L

:\PWIN /R:E:\PWIN /C reg.dat
With the above knowledge, together with what was discussed in “The ‘Shortcut’ to Programming the Registry” about importing or exporting registry files (*.REG), we can program the registry under DOS mode.
Let us still take changing the default open method for “*.txt” files—from “Notepad” to “WordPad”—as an example. First export the “HKEY_CLASSES_ROOT\txtfile” subkey branch at the MS-DOS prompt, that is, execute the command:
regedit /E txt.reg HKEY_CLASSES_ROOT\txtfile
Then use the DOS EDIT editor to open the txt.reg file for editing: change all occurrences of “C:\\WINDOWS\\NOTEPAD.EXE” to “C:\\WINDOWS\\WRITE.EXE”, save and exit EDIT, then execute the command at the command line:
regedit txt.reg
and the job is done.
Of course, strictly speaking, this is not programming. If you really want to implement it through programming, we can write the above process into a batch file
chang.bat:
@echo off
path=c:\windows;c:\windows\command;c:\dos
cls
echo Exporting the registry...
regedit /E txt.reg HKEY_CLASSES_ROOT\txtfile
echo.
echo Registry export completed! Press any key to start editing the registry...
echo.
pause
edit txt.reg
echo Importing the modified registry...
regedit txt.reg
echo Congratulations! You have successfully modified the registry under MS-DOS mode!
pause
cls
@echo on
By fully bringing out the powerful features of the EDIT editor, as long as we follow the format of the exported registry file, we can modify, delete, or add any subkey in the registry as we wish. If you feel this still is not programmatic enough, you can make use of the advantages of various programming languages under the DOS environment, add an interactive interface, and truly turn this process into a program. The result should be in no way inferior to what can be achieved under Windows using API functions. Interested friends can give it a try.