Edit the registry from a bat file
Results 1 to 3 of 3

Thread: Edit the registry from a bat file

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    2

    Edit the registry from a bat file

    Hello. I am trying to edit the registry automatically possibly from a bat file. I have not been able to find a a way to do this sucessfully. The aim of part of the bat file will be to set the wall paper key. Does any one know the best way to do this, is it possible to do it automatically from something like a bat file, or are there any alternative methods which might work better. Thanks for any advice, al.

  2. #2
    Driver Terrier NooNoo's Avatar
    Join Date
    Dec 2000
    Location
    UK
    Posts
    31,824
    Welcome to Windrivers alistair91

    Normally I would link a page, but this one is not available right now, so here is the google cache for it

    REGEDIT


    Warning:
    Before tweaking the registry, make sure you have a full backup of your system. If anything goes wrong, you may end up losing all your data and reinstalling Windows.
    As Microsoft states it, editing the registry "... is not supported by Microsoft. Use this method at your own risk."

    Windows NT (and 2000) users, read Microsoft's Knowledge Base article Q318149 to learn How to Maintain Current Registry Backups in Windows NT 4.0 and Windows 2000.



    General Syntax:
    GUI mode: REGEDIT.EXE

    Import (merge) a .REG file: REGEDIT.EXE [ /L:system ¦ /R:user ] [ /S ] importfile.REG

    Export to a (.REG) file: REGEDIT.EXE [ /L:system ¦ /R:user ] /E exportfile "registry_key"

    Compress the registry (Windows 98 only): REGEDIT.EXE [ /L:system ¦ /R:user ] /C

    Parameters: importfile.REG .REG file to be imported (or "merged") exportfile File name the information should be written to "registry_key" Registry key to be exported e.g. "HKEY_CLASSES\ROOT\*\shell" /S Silent, i.e. hide confirmation box when importing files /E Export registry file /L:system Specify the location of the system.dat to use /R:user Specify the location of the user.dat to use /C Compress [filename] (Windows 98 only)

    REGEDIT is usually known as a GUI tool to search or edit the Windows registry.
    I would not have mentioned it here, however, if it couldn't be used in unattended mode as well.


    This page focuses on reading and editing the registry in unattended mode only.

    Microsoft's NT 4 Workstation and Server Resource Kits come with REG.EXE, a utility that makes reading (or editing) NT's registry easier.
    In Windows 2000 and later, REG.EXE is a native command.
    REG.EXE can read a single key and value directly, without the need for a temporary file.
    Click here to learn more about using REG.EXE.

    Adding and editing (importing) registry entries
    Adding items to the registry requires a *.REG file: REGEDIT /S addsome.REG The /S swith is optional, it skips the message dialogs before and after the import of the *.REG file.

    Since .REG files are in readable ASCII, they may be created "on the fly" by our batch files.
    This is demonstrated in the DefOpen example in the Examples section.

    Owners of a copy of the NT 4 Resource Kit or Windows 2000/XP/Server 2003 can also use REG.EXE to add or edit registry entries.

    Removing registry entries
    To remove an entire "tree" from the registry using REGEDIT and a .REG file, just add a minus sign before the tree name: REGEDIT4 [-HKEY_CURRENT_USER\DummyTree] will remove the entire tree "DummyTree".

    To remove an individual item from the registry, place the minus sign after the equal sign: REGEDIT4 [HKEY_CURRENT_USER\DummyTree] "ValueToBeRemoved"=- will remove the individual value "ValueToBeRemoved" from "DummyTree".
    This is demonstrated in the uniqueid.bat example below, a batch file that forces a new LANDesk agent ID.

    More info can be found at Regedit.com's Registry FAQ.

    How to remove an individual registry key or value using *.INF files and RUNDLL is explained here by Bill James.

    NT users who own a copy of the NT 4 Resource Kit can also use REG.EXE to remove registry entries.

    Reading (exporting) from the registry
    REGEDIT's /E switch can be used to export a registry key: REGEDIT /E d:\path\filename.REG "HKEY_XXXX\Whatever Key" This will write the registry key "HKEY_XXXX\Whatever Key" and its subkeys to a file named d:\path\filename.REG

    The resulting (ASCII) file will contain the entries in the format "key"="value" which can be stripped and parsed using Laurence Soucy's CHOICE trick (How-to #4, second method) for MS-DOS 6 and Windows 9*, NT's FOR /F or the more generic TYPE and FIND commands.

    NT users who own a copy of the NT 4 Resource Kit can also use REG.EXE to read the registry.

    Examples
    Windows 95/98
    A fine example of reading the registry in Windows 95/98 is CDROM.BAT, which also demonstrates the use of CHOICE to strip characters (in this case the quotes) from a string.

    All Win32 Versions
    The following batch file, DEFOPEN.BAT, will create a temporary .REG file and then use REGEDIT to merge it.
    Running this batch file once (!) will create a default association to Notepad.exe (double-clicking a file without a file association will open the file in Notepad) and add three menu entries to the right mouse button menu: "Open with Notepad", "Print with Notepad" and "Command Prompt Here". The latter will be shown, no matter wether a file or directory is clicked.
    [Notepad registry tip courtesy of Regedit.com] @ECHO OFF :: No parameters required IF NOT [%1]==[] GOTO Syntax :: Choose the correct command processor for the current operating system SET _cmd= :: Variable to add shortcut to menu entry (NT only, :: since COMMAND.COM cannot echo an ampersand) SET _= ECHO.%COMSPEC% ¦ FIND /I "command.com" >NUL IF NOT ERRORLEVEL 1 SET _cmd=command.com /e:4096 ECHO.%COMSPEC% ¦ FIND /I "cmd.exe" >NUL IF NOT ERRORLEVEL 1 SET _cmd=cmd.exe IF [%_cmd%]==[cmd.exe] SET _=^& :: Create a temporary .REG file > "%Temp%.\DefOpen.reg" ECHO REGEDIT4 >>"%Temp%.\DefOpen.reg" ECHO. ECHO Adding "Open with Notepad" entry >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\*\shell\open] >>"%Temp%.\DefOpen.reg" ECHO @="%_%Open with Notepad" >>"%Temp%.\DefOpen.reg" ECHO. >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\*\shell\open\command] >>"%Temp%.\DefOpen.reg" ECHO @="notepad.exe \"%%1\"" >>"%Temp%.\DefOpen.reg" ECHO. ECHO Adding "Print with Notepad" entry >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\*\shell\print] >>"%Temp%.\DefOpen.reg" ECHO @="%_%Print with Notepad" >>"%Temp%.\DefOpen.reg" ECHO. >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\*\shell\print\command] >>"%Temp%.\DefOpen.reg" ECHO @="notepad.exe /p \"%%1\"" >>"%Temp%.\DefOpen.reg" ECHO. :: If neither COMMAND.COM nor CMD.EXE then skip this step IF [%_cmd%]==[] ECHO Skipping "Command Prompt Here" entry IF [%_cmd%]==[] GOTO Merge ECHO Adding "Command Prompt Here" entry :: Add Command Prompt Here for files >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\*\shell\prompt] >>"%Temp%.\DefOpen.reg" ECHO @="Command Prompt Here" >>"%Temp%.\DefOpen.reg" ECHO. >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\*\shell\prompt\command] >>"%Temp%.\DefOpen.reg" ECHO @="%_cmd% /k cd \"%%1\\..\"" >>"%Temp%.\DefOpen.reg" ECHO. :: Add Command Prompt Here for directories >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\Directory\shell\prompt] >>"%Temp%.\DefOpen.reg" ECHO @="Command Prompt Here" >>"%Temp%.\DefOpen.reg" ECHO. >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\Directory\shell\prompt\command] >>"%Temp%.\DefOpen.reg" ECHO @="%_cmd% /k cd \"%%1\"" >>"%Temp%.\DefOpen.reg" ECHO. :: Add Command Prompt Here for drives >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\Drive\shell\prompt] >>"%Temp%.\DefOpen.reg" ECHO @="Command Prompt Here" >>"%Temp%.\DefOpen.reg" ECHO. >>"%Temp%.\DefOpen.reg" ECHO [HKEY_CLASSES_ROOT\Drive\shell\prompt\command] >>"%Temp%.\DefOpen.reg" ECHO @="%_cmd% /k cd \"%%1\"" >>"%Temp%.\DefOpen.reg" ECHO. :: Merge the temporary .REG file :Merge START /WAIT REGEDIT /S "%Temp%.\DefOpen.reg" :: Delete the temporary .REG file DEL "%Temp%.\DefOpen.reg" :: Ready GOTO End :Syntax ECHO. ECHO DefOpen.bat, Version 3.00 for Windows 95/98/NT 4/2000/XP ECHO Adds a default association: when a file without a file association ECHO is double-clicked, it will be opened with Notepad. ECHO Adds three new entries to the right mouse button menu as well: ECHO "Open with Notepad", "Print with Notepad" and "Command Prompt Here". ECHO. ECHO Usage: DEFOPEN ECHO. ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com ECHO Notepad registry tip courtesy of Regedit.com ECHO http://www.regedit.com :: Clean up variables and quit :End SET _cmd= SET _=





    http://www.robvanderwoude.com/regedit.html
    Never, ever approach a computer saying or even thinking "I will just do this quickly."

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    2
    Superb, thanks.

Similar Threads

  1. [RESOLVED] creating a bat file to remove registry entries
    By mjbauer in forum Windows 95/98/98SE/ME
    Replies: 4
    Last Post: March 22nd, 2008, 08:54 PM
  2. XP registry file not compatible with 98?
    By ClickHere2Surf.com in forum Tech-To-Tech
    Replies: 5
    Last Post: June 28th, 2004, 10:33 PM
  3. Replies: 4
    Last Post: September 26th, 2001, 08:39 AM
  4. registry error ---new info (Edit)
    By NJLAX8 in forum Hard Drive/IDE/SCSI Drivers
    Replies: 4
    Last Post: June 17th, 2001, 04:59 PM
  5. Error on startup
    By jasonflorida1 in forum Tech-To-Tech
    Replies: 5
    Last Post: October 12th, 2000, 08:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •