Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

batch file to delete registry keys

Long story short, I have a bunch of computera failing a specific windows update because of keyboard layouts. I have found that by deleting these layout keys in the registry the update installs. So I need to deploy a batch file to multiple remote computers that will delete all of these registry keys.

So this is what's needed: Delete HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Keyboard Layouts\Subkey (about 23 Subkeys)

yes I have all the subkeys written down, just need to know how to create a batch file to do this.

 

 

0

Comments

13 comments
Date Votes
  • Hi Jason,

    Well, since you will want to keep the Keyboard Layouts key and some of its subkeys you can just write a quick and dirty bat file. Since you are force deleting registry keys I would recommend that you put a little bit of protection in your script (to prevent accidental execution). 

    Here is an example. Note that if the first parameter is not 

    rem

    then the script will not delete the keys and will exit with an error code 2. Below is an example for you:

    @ECHO OFF
    IF %1 == rem (
    GOTO DelKeys
    ) ELSE (
    GOTO NoDel
    ) :DelKeys REG DELETE HKLM\System\CurrentControlSet\Control\Keyboard Layouts\00000401 /f REG DELETE HKLM\System\CurrentControlSet\Control\Keyboard Layouts\00000402 /f REG DELETE HKLM\System\CurrentControlSet\Control\Keyboard Layouts\00000403 /f GOTO :EOF :NoDel
    echo "will not delete"
    exit 2

    Make sure you add the parameter, rem, to your PDQ Installer parameters field.

    DeleteRegKeysExample.png

     

     

     

     

     

    0
  • Thanks Shane, that worked perfectly... just had to take out the Echo's and run it silently so as to not disturb the end user. I really appreciate it

    0
  • No worries, Jason. Thanks for letting us know how it went. FYI - The end user wouldn't see the echos or indeed any of the deployment progress. PDQ Deploy runs the installers silently so the end users don't know whats going on.

    0
  • Also... a little glaring oversight on my part. It's not a good idea to have the parameter be "rem" only because REM is generally used to remark out code in bat files. This script will still work but it breaks the convention and I definitely deserve a groin punch for putting that in.

    0
  • ok, will take it out.. thanks again

    0
  • Hi Shane I have followed your method here to add alter a registry entry so we can remote into the PC I have a bat fille called AddRD.bat with just the 1 line Reg.exe ADD "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_WORD /d 0 /f But fails with error code 1
    0
  • ooops sorry Shane left out the D in DWORD working now
    0
  • hey guys... do u know how to make a protected bat file from deletion???

    0
  • Hi Andie,

    I want to make sure I understand. Are you wanting to create a batch file that can't be deleted? If you do then there are  few things you can do to make it more difficult to delete.

    1) Mark it as read only. You can do this by right clicking on the bat file and selecting Properties. Under the Attributes section of the General tab check the Read-only box. To do this from a command line you would run a command similar to:

    attrib +R %PUBLIC%\Desktop\runme.bat

    Obviously place the correct path and file name for your batch file.

    You can also set file permissions on it (via Properties > Security) or via the icacls command.

    0
  • I am really struggling to figure out how to write a working script to find and delete registry keys/values.  After spending almost 2 hours trying to figure this out, I am throwing my hands up in the air and hoping that Shane or someone else can help me!  Here is what I have written so far:

    @echo off
    REM I'm sure there is a more elegant way of doing this,
    REM but this is what I came up with, lol!

    REG QUERY "HKLM\software\!shuey test 1"
    IF "%ERRORLEVEL%"=="0" REG DELETE "HKLM\software\!shuey test 1" /f
    IF "%ERRORLEVEL%"=="1" GOTO N01

    :N01
    REG QUERY "HKLM\software\!shuey test 2"
    IF "%ERRORLEVEL%"=="0" REG DELETE "HKLM\software\!shuey test 2" /f
    IF "%ERRORLEVEL%"=="1" GOTO N02

    :N02
    REG QUERY "HKLM\software\wow6432node\!shuey test 3"
    IF "%ERRORLEVEL%"=="0" REG DELETE "HKLM\software\wow6432node\!shuey test 3" /f
    IF "%ERRORLEVEL%"=="1" GOTO N03

    :N03
    REG QUERY "HKLM\software\wow6432node\!shuey test 4" /v shueytest4
    IF "%ERRORLEVEL%"=="0" REG DELETE "HKLM\software\wow6432node\!shuey test 4" /v shueytest4" /f
    IF "%ERRORLEVEL%"=="1" GOTO N04

    :N04
    REG QUERY "HKLM\software\wow6432node\{shuey-test-5}"
    IF "%ERRORLEVEL%"=="0" REG DELETE "HKLM\software\wow6432node\{shuey-test-5}" /f
    IF "%ERRORLEVEL%"=="1" GOTO N05

    :N05
    EXIT

    0
  • I ended up figuring out a much simpler way of handling my issue.  Here is the code I ended up using:

    @echo off

    reg delete "HKLM\software\!shuey test 1" /f>nul
    reg delete "HKLM\software\!shuey test 2" /f>nul
    reg delete "HKLM\software\wow6432node\!shuey test 3" /f>nul
    reg delete "HKLM\software\wow6432node\!shuey test 4" /v shueytest4 /f>nul
    reg delete "HKLM\software\wow6432node\{shuey-test-5}" /f>nul

    0
  • HELLO....

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Entre Computer Services\EScreenz]
    "ServiceUrl"="http://wardfuel/escreenzproxy"
    "DisplayMode"="Force"
    "InstallPath"="C:\\Program Files\\Entre Computer Services\\EScreenz 2.2.11\\"
    "MasterLoaderRefreshInterval"=dword:00007530
    "DiagnosticMode"="False"
    "MasterLoaderUdpPort"=dword:00000050
    "OverrideSlideDelay"="False"
    "WindowedMode"="False"
    "AutoStartLoader"="True"
    "OverrideSlideTimeout"=dword:000003e8
    "RespondToMouseEvents"="False"
    "Trace"="True"
    "EScreenzVersion"="2.2.11"

      I EXPORTED THIS REGISTRY KEY IN ORDER TO MODIFIED ONE VALUE WHICH IS "ServiceUrl"="http://AAAAAA/escreenzproxy".

    I WANT TO CHANGED IT TO "ServiceUrl"="http://BBBBBBB/escreenzproxy"

    I ALREADY TRY I FEW THINGS BUT IT DIDNT WORK.

    ANY IDEA PLEASE.

    THANKS

    0
  • Hi,

    interesting post , but I looking for a way to delete all keys containing the same string.

    It is a vendor string so no problem to remove it.

    Thanks

    0