Reg query/Reg delete key with embedded & failure - batch-file

I am attempting to perform a registry query as per the following in a Win XP reg v3.0 via batch file environment:
reg query /v HKLM\SOFTWARE\DSAC\usb\vid_08ec&pid_204c
I am receiving argument errors truncating at the &. If I escape ^&, the query parses the full key but fails to locate the registry key because, I believe, the search key is then vid_08ec^&pid_204c.
Can anyone advise how I can achieve this reg query and deletion against the vid_08ec&pid_204c string?

Try like this :
reg query /v "HKLM\SOFTWARE\DSAC\usb\vid_08ec&pid_204c"

Related

How to use FINDSTR inside of a FOR loop to delete registry keys?

I want to delete all *.bak profile registry keys off all computers at work.
We gave everyone temporary profiles a while back, and we're trying to remove them now. The .bak registry keys are forcing temp profiles where people don't want them.
I have this command that LISTS all the *.bak registry keys:
for /f %f in (windowscomputers.txt) do reg query "\\%f.mydomain.com\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" | findstr /E bak
But that just lists them. I need to delete them.
And I TRIED to delete the *.bak keys off of just one workstation as a test:
for /f %f in ('reg query "\\workstationFQDN\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" ^| findstr /e bak') do reg delete \\workstationFQDN\%f
The above tries to delete \\workstationFQDN\HKLM\SOFTWARE\Microsoft\Windows. Even though I have "" around the path, it's breaking at the space between Windows and NT.
How do I use findstr inside of a for loop, so that it executes on each of the registry keys that findstr finds?
After that, I need to do a nested for loop so that it deletes each of the .bak registry keys that findstr finds, on each of the computers in my text file windowscomputers.txt.
This is a basic question. I tried googling findstr reg query for loop, and found lots of batch script examples that frankly went over my head, using options like tokens=, delims=, and %~ that I've read about in the for /? help file, but don't understand their usage or how it might apply to my specific need (delete each .bak profile registry key on each computer at work).
I've also only used one-liners in cmd prompt. I understand that batch has some syntax differences if I need to use multiple commands, like %%f instead of %f.
Try
for /f "delims=" %f ...
(And echo the reg delete... just to be safe)
(also - quote the string being deleted)
%f is referred to as a metavariable. Metavariables require one % directly from the prompt, buttwo if used within a batch file.
From the prompt, use for /? |more for (somewhat cryptic) documentation about the delims= (and other) options. Or look through some examples here on SO.
(as a batch line) the following listed the appropriate keys for me (I can't duplicate your setup)
FOR /f "tokens=1*delims=\" %%q IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"') DO ECHO %%r
Prefixing "HKLM" above with "\machinename\" and filtering using a findstr filtered out the unwanted lines. %%r contained \software\..., so all you'd appear to need is to pop the prefix string \\machinename\HKLM\ before that and your command should be ready-to-go.

Clear the PendingFileRenameOperations registry value

One of my troubleshooting steps is to clear the PendingFileRenameOperations registry value to avoid rebooting a server.
What I would like to do is clear this through a batch file, I don't want to delete it, just clear it.
It's the following registry value
HKEY_LOCAL_MACHINE/SOFTWARE/Session Manager/PendingFileRenameOperations
The command
%SystemRoot%\System32\reg.exe add "HKLM\System\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations /t REG_MULTI_SZ /d "" /f
replaces current value of multi-string value PendingFileRenameOperations with an empty string.
The path you wrote in the question does not exist on my Windows 7 x64 machine.
For details on command reg open a command prompt window and run there first reg /? and second reg add /?
But why clearing this registry value used to delete or replace (usually update) files after reboot before Windows loads drivers and starts processes and applications should avoid rebooting a Windows server is beyond my understanding.
Some software just checks for the key existence and doesn't care if its blank,So For deleting Key,Use My Way :
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations /f

Registry Duplicate Key

So I am writing one of my first large batch scripts and part of the script needs to create several keys in the registry. The problem I am having is that a redundant subordinate key is being created in the path and I am not sure how to solve it. Also of note is that this only occurs on certain systems and is not always the case.
Here is the command I am using:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Riedel\ARTIST SNMP Agent" /v "MasterSnmpAgentIpAddr" /t REG_SZ /d "127.0.0.1:705"
When I look in the registry to see the result, here is the path that it is placed in:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Wow6432Node\Riedel\ARTIST SNMP Agent
I've tried a few methods of creating registry keys, but they yield the same results. Any thoughts or help would be appreciated. Thanks!
Wow6432Node is for the 32bit programs in 64bit OS. So you should better use the reg add switch /reg:
try this for 32bit entries
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Riedel\ARTIST SNMP Agent" /v "MasterSnmpAgentIpAddr" /t REG_SZ /d "127.0.0.1:705" /reg:32
and for 64bit
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Riedel\ARTIST SNMP Agent" /v "MasterSnmpAgentIpAddr" /t REG_SZ /d "127.0.0.1:705" /reg:64

Reading child registry key from regedit in batch file

I want to read a registry key's child key name and assign the child key name to a variable. I am not getting an registry query to do it.
For ex: My current key is like this "ProviderName/SoftwareName/8.0". The last part 8.0 can change as and when I switch versions. I would want to read this version number.
Thanks in advance !!
Prakash
the REG command is what you will have to parse the output for.
REG QUERY HKLM\Software\Microsoft\Office
will show you office versions (as well as some common keys)
for /f "tokens=5 delims=\" %a in ('REG QUERY HKLM\Software\Microsoft\Office') do echo %a
will output the information. you will have to convert the info into a number, then test to see if it is bigger.

Removing a registry key and its subkeys using a batch

I need to remove a registry key (including its subkeys) from a batch file.
The examples I found led me to the following code but the key remains?
#ECHO OFF
REG DELETE "HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Profiles\STDPROFILE" /V
Not so good at batch programming, but
reg query "HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Profiles\STDPROFILE" /s > toDelete.txt
for /f %v in (toDelete.txt) do reg delete %v
the first line puts every key and value in a file, then the loop reads them and calls reg delete

Resources