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.
Comments
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
then the script will not delete the keys and will exit with an error code 2. Below is an example for you:
Make sure you add the parameter, rem, to your PDQ Installer parameters field.
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
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.
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.
ok, will take it out.. thanks again
hey guys... do u know how to make a protected bat file from deletion???
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:
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.
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
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
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
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