Reg Delete Batch File - windows

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

Related

How to delete registry entry with batch command?

I want to delete a specific entry in registry. The path is this
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\3rdparty\Extensions\heildphpnddilhkemkielfhnkaagiabh\policy\url_list
Then in the path, there is a specific entry with name 4 and entry server.com.
I found this
REG DELETE "HKEY_CURRENT_USER\SOFTWARE\SomeProgram" /v "EntryName"
but how do I get it to delete by value? I want to enter server.com instead of 4.
The command line allows just the deletion of keys but not their values.You can use an alternative by overwriting the value by what you want
Use :
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\3rdparty\Extensions\heildphpnddilhkemkielfhnkaagiabh\policy\url_list /v "EntryName" /t REG_SZ /d example.com

REG add Doesn't Run

I've written a batch file that tests for a user's Microsoft Office version, copy an Excel Add-In to their device from a shared drive, and add a registry key to their device.
Each individual action in the batch works as designed. But when I combine them all together, the file doesn't like the REG add command and completely closes the command window (even if I put Pause after the REG add line).
To troubleshoot, I created a new batch file and added pieces of my code to it, one section at a time, and tested the file each time a new section was added. Every section ran fine until I got to this section:
CHDIR "C:\Windows\System32"
IF NOT %ALREADY_ENABLED%=="TRUE" (
REM Add the new key value if it doesn't exist already.
REG add HKCU\Software\Microsoft\Office\15.0\Excel\Options /v OPEN /t REG_SZ /d "%PATH%" /f
)
To see if the problem was my IF statement, I commented out the REG add line and put ECHO Hello World inside the IF statement. The file ran just fine and gave the Hello World output as expected.
I know the REG add command works because I have a batch file that only includes that piece of code and it works just fine:
#Echo off
setlocal enableDelayedExpansion ENABLEEXTENSIONS
chdir "C:\Windows\System32"
SET PATH=\"C:\Program Files (x86)\Microsoft Office\Office15\Library\Cerner_AddIn.xlam\"
REG add HKCU\Software\Microsoft\Office\15.0\Excel\Options /v OPEN /t REG_SZ /d "%PATH%" /f
I think the problem has something to do with the PATH variable, but I'm dumbfounded as to why this works in one file but not the other. Is it possible that the value of PATH is somehow changing during runtime after it's been set?
I'm not sure how to trap the error to even see what error is being thrown here. Everything I've tried to handle the error with doesn't work and the command window closes. Any ideas on what I'm doing wrong here?
Maybe this code snippet could help:
SET "myPATH=C:\Program Files (x86)\Microsoft Office\Office15\Library\Cerner_AddIn.xlam"
IF NOT "%ALREADY_ENABLED%"=="TRUE" (
REM Add the new key value if it doesn't exist already.
REG add HKCU\Software\Microsoft\Office\15.0\Excel\Options /v OPEN /t REG_SZ /d "%myPATH%" /f
)
Note:
do not change system environment variable PATH; use another variable name (myPATH);
quoting in set "variablename=variable value";
quoting in if statement;
to trap any error in a batch file, use echo ON while debugging.
Resources (required reading):
(command reference) An A-Z Index of the Windows CMD command line
(additional particularities) Windows CMD Shell Command Line Syntax

REG command after SET is "unknown" in DOS/Windows batch file (.BAT)

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.

Adding a new registry file through batch commands

So I've been trying to add a new registry key and it's been working fine, noting the fact that this addition is not going to harm my computer it's just for me to understand a few concepts. The problem that's been happening is as follows, when I run my batch file, it's displaying the following message in cmd:
off REG ADD HKLM\Software\Hello - 24919 /v Test /t REG_BINARY /d fe340ead
the "off" in bold is a little weird, I'm not sure what happened for it to appear and not add the key, like I said I'm using batch commands and basically writing to another batch file through my initial batch file and this is the code I used:
#echo off
set new=new2.bat
echo #echo off REG ADD HKLM\Software\Hello - %random% /v Test /t REG_BINARY /d fe340ead >>%new%
Help is appreciated please! and thank you!
PS: I've referred to the following question (adding a random key to the registry through a batch file) , and did exactly the same, it worked once but then I don't know what happened for the above to show and not add the key.
#echo off
set new=new2.bat
(
echo #echo off
echo ^>nul REG ADD "HKLM\Software\Hello - %random%" /v Test /t REG_BINARY /d fe340ead
) > %new%
You need to place the #echo off and the REG ADD in separate lines

Registry Query - Bat file

I want to loop through all registry entries in a certain path and see if any of those match a string. I have the below bat file command:
reg query HKLM /f Software\Microsoft\Windows\CurrentVersion\Uninstall /v ProductName /s|findstr /r "abc - def (x64)"
I am using the %errorlevel% to determine the output of the above command. Expecting 0 when a registry exactly matching is found and non-zero when such a registry is not found.
However, I am getting 0 in both cases, i.e. a registry matches the string or it it doesn't.
Can you please suggest any correction to my bat command.

Resources