Tom Eason
asked on
Delete Reg key only if empty via batch
I'm working on a batch file. What I want to do is delete a reg key if there are no other sub-keys
ex. "HKLM\Software\Vendor" is the key I want to delete. Don't delete it if "HKLM\Software\Vendor\Prod uct" exists
ex. "HKLM\Software\Vendor" is the key I want to delete. Don't delete it if "HKLM\Software\Vendor\Prod
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> I don't know what the 'product' key would be.
It doesn't matter what word it is. 'product' is just a word I used.
> I want to delete HKLM\Software\Dell only if there are no keys beneath that layer.
So, change it to...
Also, There's an error on line 6. Change the \\ to \
It doesn't matter what word it is. 'product' is just a word I used.
> I want to delete HKLM\Software\Dell only if there are no keys beneath that layer.
So, change it to...
set keyname=dell
Also, There's an error on line 6. Change the \\ to \
ASKER
I made that change to set keyname and saw the \\.
The mistake I was making was not running it as Administrator. Once I did that it worked fine.
Thanks!
The mistake I was making was not running it as Administrator. Once I did that it worked fine.
Thanks!
ASKER
This line confused me at first, "REG QUERY "HKEY_LOCAL_MACHINE\Softwa re\%keynam e%" /s | find /i "%keyname%\" " Then I noticed the final '\' it made sense. This line was very helpful too "if !errorlevel! neq 0".
Glad you ve studied the code. Thanks for the update. There may be a better way to do it but this works i guess. Have a good one
ASKER