Edit registry with a batch file

I am new to this forum, I just purchased a months time so I can get a job done. I am also fairly new with dos, though I know the windows OS very well.
Here's my question:
I need to edit the registry with a batch file, more precisely, I need to empty the "Recent" folder, MRU's, Recycle Bin, URL history in IE, and be able to add a line to autoexec.bat or remove the line.
Can someone please help me out?
Oh, and this is for Windows XP
Thanks!
Tags: registry  batch  file  edit 
  • Answer #1:

    Not clear about whether you wat to edit the registry or delete the recent folder , recycle bin or URL history. All of these are folders and contain files which when deleted can remove whatever hostory you don't need.

    However editing the registry can be risky thru a batch file. Also i have no idea if a line can be removed from autoexec.bat however adding a line is ok. You can use the >> operator of DOS to append two files so you can put the new line as a separate file.

     
  • Answer #2:

    Hi pcs800,

    There are two different things: "Recent" and the "Recylce Bin" are folders. The MRUs etc are registry settings.

    Registry settings:
    ----------------------
    Adding and removing branches to the registry can be done by using "regedit.exe" from the command prompt or from a batch file. First use "regedit.exe" - "registry" - "export registry file" to export a registry file from the GUI, than you can see the syntax of the .reg file.

    for adding a key I used the file "add_test.reg"
    ---SOF---
    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\testkey]
    "testvalue"="12345"
    --- EOF ---

    for deleting a key I used the file "remove_test.reg"
    --- SOF ---
    Windows Registry Editor Version 5.00

    [-HKEY_LOCAL_MACHINE\SOFTWARE\testkey]
    "testvalue"="12345"
    --- EOF ---

    Adding is than accomplished by typing "regedit /s add_test.reg", deleting by typing "regedit /s remove_test.reg" in a command box. /s surpresses the dialog box. The - in front of the HKEY removes the key. To remove only one value use "testvalue"=-

    I know some of the registry branches you asked for:
    HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs -- the URLs you typed in IE (!CURRENT_USER!)
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU -- the commands you typed in "start"-"run"

    If there are more things you want to delete you have to search them yourself. Be carefull with regeistry settings - store _EVERYTHING_ you delete separatly and delete only things from which you know what they are supposed to do.

    The folders:
    ---------------
    The recylce bin" is a hidden system folder: Usually "C:\RECYLCER" (in the explorer use "tools"-"folder options" - "view" and show all folders and files with extensions) There are long subfolders like "S-1-5-21-54938807-1984772358-980507067-74305" They contain the deleted things. I _do not know_ what happens if you delete things here!

    The "Recent folder" is: "C:\documents and settings\<username>\Recent" - here you can delete all shortcuts trouble-free.

    regards,
    Vince
  • Answer #3:

    So if i wanted to delete the key:
    HKCU\Software\Microsoft\Internet Explorer\TypedURLs

    I use what commands in a batch file?
    and i do not know what SOF and EOF are, sorry I'm new.
  • Answer #4:

    Hi,

    there are more than the keys mentioned above
    HKEY_USERS\S-1-5-21-54938807-1984772358-980507067-74305\Software\Microsoft\Internet Explorer\TypedURLs
    HKEY_USERS\S-1-5-21-54938807-1984772358-980507067-74305\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU

    Regards, Vince
    PS: I use win2000 - the behaviour of XP should be similar
  • Answer #5:

    tried the following (pause id so I can see what it did, or any errors)

    regedit /s remove_HKCU\Software\Microsoft\Internet Explorer\TypedURLs
    pause

    did not do anything.
  • Answer #6:

    i think i figured out SOF and EOF
    start of file, end of file?
  • Answer #7:

    does this hide all output? I do not want to see the commands in the dos box.

    Ok, I copied and pasted the above code into a batch file, and it did nothing. Are you sure it's %userprofile%, because i had to use %username% in the batch files I created to empty folders.
  • Answer #8:

    Here's an example of a batch file which creates a "purge" registry patch for the CURRENT USER ONLY and removes the temp files. It should illustrate the concepts.


    @ECHO OFF
    cls
    Echo Clearing Recent and Favorites shortcut files...
    del /q "%USERPROFILE%\Recent\*.*        >NUL
    del /q "%USERPROFILE%\Favorites\*.*    >NUL
    echo.
    echo Creating Registry file...
    echo REGEDIT4 >%USERPROFILE%\Remove.Reg

    echo.
    echo Adding remove keys for Explorer and Internet Explorer...
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs] >>%USERPROFILE%\Remove.Reg
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU] >>%USERPROFILE%\Remove.Reg

    echo.
    echo Adding "remove" key for Excel 2000 MRU list...
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Excel\Recent Files] >>%USERPROFILE%\Remove.Reg

    echo.
    echo Adding "remove" key for Powerpoint 2000 MRU list...
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\PowerPoint\Recent File List] >>%USERPROFILE%\Remove.Reg

    echo Now removing the registry keys...
    regedit /S %USERPROFILE%\Remove.Reg

    echo Now purging Deleted Files...
    cd %systemdrive%\Recycler
    del /q/s .\*.*

    Hope this helps...
  • Answer #9:

    actually, I am not too concerned with excel and powerpoint and other office programs mru's right now.
    I would like to concentrate on the typed url list.

    so the following should work? but doesn't

    echo.
    echo Adding remove keys for Explorer and Internet Explorer...
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs] >>%USERPROFILE%\Remove.Reg
  • Answer #10:

    I changed it a bit, and got the favorites and recent to empty out, but the excel and powerpoint, and recycler do not work. Here's what i have.

    @ECHO OFF
    cls
    Echo Clearing Recent and Favorites shortcut files...
    del /q "%USERPROFILE%\Recent\*.*"        >NUL
    del /q "%USERPROFILE%\Favorites\*.*"    >NUL
    echo.
    echo Creating Registry file...
    echo REGEDIT4 >%USERPROFILE%\Remove.Reg

    echo.
    echo Adding remove keys for Explorer and Internet Explorer...
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs] >>%USERPROFILE%\Remove.Reg
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU] >>%USERPROFILE%\Remove.Reg

    echo.
    echo Adding "remove" key for Excel 2000 MRU list...
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Excel\Recent Files] >>%USERPROFILE%\Remove.Reg

    echo.
    echo Adding "remove" key for Powerpoint 2000 MRU list...
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\PowerPoint\Recent File List] >>%USERPROFILE%\Remove.Reg

    echo Now removing the registry keys...
    regedit /S %USERPROFILE%\Remove.Reg

    echo Now purging Deleted Files...
    cd %systemdrive%\Recycler
    del /q/s .\*.*

    for recycler it says "cannot find c:\recycler", I checked and yes it's there.
  • Answer #11:

    To get this doing what it is supposed to do use
    echo [-HKEY_CURRENT_USER\ ... ] >> "%USERPROFILE%\remove.reg"

    This does nothing either. (of course i put in the rest of the path)
    Your batch file in the newer question thread works, but prompts me, and does not remove all url history, and also puts the typed url's back after it removes them.
  • Answer #12:

    Your echo command is ok - except if there are blankspaces in %userprofile%. If your %userprofile% is "c:\documents and settings\<username>\... have a look for a file c:\documents

    To get this doing what it is supposed to do use
    echo [-HKEY_CURRENT_USER\ ... ] >> "%USERPROFILE%\remove.reg"            (the double quotes " are important)


    For the Recycle Bin: (confirm this on your own machine - I did _NOT_ test very much) there seems to be a strange behaviour.
    If I try to delete everything in c:\recycler with the explorer (folders like S-1234-23456-3456 and all hidden and system files) I am not allowed to.
    If I go into a dosbox and cd to c:\recycler and use "rmdir /S /Q S-1-5-21-54938807-1984772358-980507067-74305" the folder gets deleted with all its containing files. _BUT_ the symbol on the desktop is still "filled" but I cannot use "rightclick-empty recycle bin"

    This rmdir /S /Q should work from any batchfile too. If you need to know which folders are in the folder c:\recycler use "dir /AD" Perhaps have an other look at "dir /?" "rmdir /?" "del /?" and "attrib /?"

    If you find the way to get the recylce bin empty perfectly - let me know. Best regards, Vince
    PS: Your big batch file should work. EOF is EndOfFile - SOF is s.th. I perhaps created - It's not common but I was to lasy to type ;)
  • Answer #13:

    If your user name has a space in it you would need to change the line to

    regedit /S "%USERPROFILE%\Remove.Reg"

    in the batch file.
  • Answer #14:

    The .bat i posted was for demonstrating the techniques. It is useless if called on every startup of windows.

    If you execute the following .bat your typed URL list will be empty. (even more - the key will be missing in the registry. That should not cause problems, IE adds the missing key again.) No prompting, no asking, you can even double click it.

    @echo off
    echo Windows Registry Editor Version 5.00 >> "%userprofile%\delete.reg"
    echo >> "%userprofile%\delete.reg"
    echo [-HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs] >> "%userprofile%\delete.reg"
    regedit /S "%userprofile%\delete.reg"
    del /Q "%userprofile%\delete.reg"

    The typed URLs are stored in
    [HKEY_USERS\S-1-5-21-54938807-1984772358-980507067-74305\Software\Microsoft\Internet Explorer\TypedURLs]
    too. I did not yet look what they are supposed to do. Anyway - to get rid of them substitue the [-HKEY_CURRENT_USER...] with [-HKEY_USERS\looooooongkey\...] in the batch file above.

    What I'm more surprised about is your "This does nothin either" Could you please be a little more precise? If I use the command exctly as shown above, a file remove.reg is created in my directory %userprofile%.
    Use the command from above, use "cd %userprofile%", use "dir" and there it is. Use "type remove.reg" to see its content. Or if something seems strange, paste more infos.

Related questions about "Edit registry with a batch file"

  • gpedit, the registry and batch files

    I want to be able to run a batch file on a stand alone windows 2000 machine that will make the default homepage in internet explorer the same for every user even if I create a new user. The only way I've been able to do that so far is
  • Need help writing a Batch file to edit the Registry for Symantec Mail Security

    The brilliant trilogy of Microsoft, Veritas and Symantec have put us non-native DOS speakers in a quagmire. Apparently, the only way to successfully complete a brick-level back-up of Exchange 2003 when using Veritas Back-up Exec with Symantec Mail Security is to edit the registry before and after the back-up job.
  • the existence of a registry key with a batch file (DOS)

    I want to be able to see if a machine has Access 97 on it or Access 2000. I decided I could check this by looking for the existence of the following key:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\9.0\AccessI need to check for the existence of this key via a batch file (DOS). I would like
  • Can I write a batch script to save a specific registry key to file?

    I need to automate the saving of a registry key to file, is it possible to write a batch command?I'm using NT4 and wish to save the reg key HKEY_LOCAL_MACHINE\SOFTWARE\TAIS to file RegKey.regThanks check the command:reg export /? You can use 'REG EXPORT'Like so: REG EXPORT HKLM\SOFTWARE\TAIS "c:\folder\RegKey.reg" You can
  • Modify the registry of Windows 2000 using a batch file.

    I want to change a registry entry of a Windows 2000 machine using a batch file. How do I do this? There are several ways. You need to be more specific on what you want to do. http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/ntwrkstn/reskit/24_reged.asp"Regini.exe Makes Registry changes by using script files."Have your batch file
Logo, design and layout © 2009 DoExpert CodeMe