Programming method of registry under DOS

Time:2021-12-2

Can the registry be programmed in DOS mode? yes. When your Windows 95 / 98 cannot start to the graphical interface due to registry problems, you can only operate on the registry under DOS. Because regedit.exe, the registry editor, is actually a dual program, which can run both under DOS and Windows95 / 98. Many users may already know how to use regedit under windows. In order to master the programming of registry under DOS mode, we must first understand how to use registry editor under DOS.
    Type the regedit command at the DOS prompt and a help screen will appear. This screen shows 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]
    Of which:
     / L:system   Specify the storage location of the system.dat file.
    / R:user   Specify the location of the user.dat file.
       filename1   Specifies the file name to bring 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   Specifies the start key of the exported registry file (all keys by default)
    Here are some examples to illustrate the use of regedit.exe under DOS.
    [example 1]   Export the system registry database registry to the reg1.reg file.
  regedit /E reg1.reg
    [example 2]   Reg1.reg is formed in the system registry database Registry (all).
  regedit /C reg1.reg
    [example 3]   Introduce reg.dat into the system registry database (section).
  regedit reg.dat
    [example 4]   Export the key from Cjh to the registry database and name it cjh.reg.    
   regedit /E cjh.reg cjh
  [example 5]   Specify that system / dat is stored in D: \ Pwin and user.dat is stored in E: \ Pwin, and the reg.dat data file is formed into a new registry database registry.
  regedit /L:D:\PWIN /R:E:\PWIN /C reg.dat
     With the above knowledge, combined with the imported or exported registry files (*. Reg) mentioned in the “shortcut” to programming the registry, we can program the registry in DOS mode.
     Let’s change the default opening method of “*. TXT” file – “NOTEPAD” to “WordPad” as an example. First, export the branch of “hkey_classes_root \ txtfile” subkey at the MS-DOS prompt, that is, execute the command:
  regedit /E txt.reg HKEY_CLASSES_ROOT\txtfile
      Then use the edit editor under DOS to open the txt.reg file for editing: change all “C: \ \ windows \ \ Notepad. Exe” into “C: \ \ windows \ \ write. Exe”, save to exit edit, and then execute the command on the command line:
  regedit txt.reg
It’s done.
      Of course, strictly speaking, this is not programming. If programming is necessary, we can write the above process as a batch file change.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 completed! Press any key to start editing the registry
   echo.
   pause
   edit txt.reg
    echo   Importing modified registry
   regedit txt.reg
    echo   Congratulations! Successfully modified the registry in MS-DOS mode!
   pause
   cls
   @echo on
Give full play to the powerful function of the edit editor. On the premise of following the format of the exported registry file, we can modify, delete or add any subkey to the registry at will. If you don’t think this is procedural enough, you can give full play to the advantages of various programming languages in DOS environment and interactive interface to truly program this process, which should be no less than the effect of using API functions in windows. Interested friends can have a try.