I wonder if it's posible to find and delete certain given registry values by the user in the Windows registry with a bat file.
For example, I want to delete all the entries wich contains the word oracle, so the bat file must delete all the entries like for example:
c:\users\user\AppData\LocalLow\Oracle\Java\jre1.8.0_101\
Microsoft OLE DB Provider for Oracle
c:\oracle\product\11.2.0\client_1\bin\OraOLEDB11.DLL
As you can see, the 3 entries has the word oracle in it. Is this possible?
Thank you very much!
There are 2 commands that will fit your requirements: reg query and reg delete.
With req query you can search for keys and/or values in the registry.
reg query <KeyName> [{/v <ValueName> | /ve}] [/s] [/se <Separator>] [/f <Data>] [{/k | /d}] [/c] [/e] [/t <Type>] [/z]
The following example searching recursive (/s) in HKCU:
reg query HKCU /s /f Oracle
To delete a registry key or value use reg delete:
Reg delete <KeyName> [{/v ValueName | /ve | /va}] [/f]
To write it in a batch you have to filter the output of reg query a bit and parse it line by line with a for /L loop. If you have trouble with that show your efforts and ask about specific problems (edit your question).
Also consider of making a backup with reg export of selected keys before you delete them.
Reg export KeyName FileName [/y]
Another great tool for such things is the PowerShell.
I tried to delete a map/key in regedit using a batch file
I used this command but this gives me an error.
REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Scaling] /v Scaling /f
I tried to remove Scaling without a Windows message
the error message:
ERROR: the system was unable to find the specified Registry key or value
ERROR invalid key name
Start Regedit and check if that key exists and has some values set:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Scaling
If it does, it's value can be changed by running the command in Admin Cmd Prompt:
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Scaling" /v Scaling /f REG_DWORD /d 96
You can also delete the entire key, but not its value, though it can be set to 0. You need to try what works for a particular setting, it may vary for different apps.
You copied a square bracket from the reg file. Remove it
DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Scaling HERE - ] /v Scaling /f
I am trying to create a module to configure my systems to point at a certain server. I need to change the registry key of the hostname of the server i require.
The way i have done this is, i have a 'params.pp' which is configured with the command i'd like to run. I also have a hiera value specifying the hostname. The idea is if the hostname ever changes, i just change the hiera value and the module does not need to change.
I am getting a syntax error for the reg.exe command (i'm using puppet exec). the issue is the following code;
$server_add = "reg.exe add HKLM\\SOFTWARE\\path\\to\\registry /f /v KeyName /t REG_SZ /d ${server}"
$server_query = "reg.exe query HKLM\\SOFTWARE\\path\\to\\registry /v KeyName | findstr.exe ${server}"
It wants the double quotes around the registry key path. The issue then is my puppet code cannot access find my variable '${server}'.
I've tried many combination with quotes and double quotes and seem to have no luck.
Any help would be great.
Thanks in advance.
For the double qoutes around the registry key, please use \" in your string:
$server_add = "reg.exe add \"HKLM\\SOFTWARE\\path\\to\\registry\" /f /v KeyName /t REG_SZ /d ${server}"
It will give you:
reg.exe add "HKLM\SOFTWARE\path\to\registry" /f /v KeyName /t REG_SZ /d
In my batch file I started to use variables and suddenly the following commands do not work anymore.
Here is the part of my code with the problem
SET "path=MyPath"
REG ADD "HKCU\Software\ETC\ETC" /f /v "MyRegNameA" /t REG_SZ /d "%path%\ETC\"
REG ADD "HKCU\Software\ETC\ETC" /f /v "MyRegNameB" /t REG_SZ /d "%path%"
PAUSE
START "" "%path%\MyProgram.exe"
This code works without the SET... and of course with MyPath instead of %path%. Error Message is:
The command "REG" is either spelled wrong or couldn't be found
I previously found how to use Variables here: stackEx.SetVariables
To my knowledge I am doing it exactly as supposed, and I couldn't find specific help so far.
path is a logical name, but it's not a good name to use as it is assigned by Windows.
path is a semicolon-separated list of the directories that Windows uses to find programs. When you change it, Windows can no longer find reg.exe since reg.exe is not in mypath.
Simply choose another name - don't use path. If you enter set at the prompt, you will see a list of many of the variables that are established by Windows. Simple rule - don't use any of them for user-variables.
To add a REG_MULTI_SZ multi-line registry value, i can do
reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc\0def\0"
which would add ("abc", "def").
But what if i need to add ("abc", "", "def"), i.e. an empty item in between?
Doing
reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc\0\0def\0"
gives me an "invalid parameter" error.
This worked for me:
REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d item1\0item2 /f
or if your items have whitespace:
REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d "item1"\0"item2" /f
Make sure you don't have TWO trailing "\0" separators (one is OK, with or without the trailing \0 you will get your last return character) like the example below (like I saw in a TechNet article), or you will get an "ERROR: Invalid value specified for '/d'.":
REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d item1\0item2\0\0 /f
This probably isn't possible using reg add, because the data you're trying to set is improperly formed. REG_MULTI_SZ values are terminated by an empty string, so having an empty string as part of the value is not allowed.
If you really need to, and on the understanding that some software won't be able to read the key correctly, you could use reg import instead. For example, the following file creates a value with an empty string in the middle:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\software\harrytest]
"test"=hex(7):76,00,61,00,6c,00,75,00,65,00,31,00,00,00,76,00,61,00,6c,00,75,\
00,65,00,32,00,00,00,00,00,76,00,61,00,6c,00,75,00,65,00,34,00,00,00,76,00,\
61,00,6c,00,75,00,65,00,35,00,00,00,00,00
Try this:
#reg.exe add "HKCU\Software\Wirkomatron" /v "MySoftware" /d "Software1"\0"Software2"\0"Software3"\0 /t REG_MULTI_SZ /f
And now you can do it with Batch script propertly.
Just for reference.
If you just want to insert a new line then you will need to simulate it with a space in the desire empty line. If the space would have an undesired impact in what you are trying to achieve then this post is not useful for you.
reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc\0 \0def\0"