# Batch File to delete registry key not working



## virtualwolf (Feb 22, 2016)

Can anyone tell me why this line in my batch file won't execute?:

REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v “C:\\Program Files\\UltraVNC\\” /f

I get this error:
ERROR: The system was unable to find the specified registry key or value.

I've tried tried it several different ways with quotes, without quotes, and with 1 \'s. I've verified the key is there and I'm running as administrator. Thanks.


----------



## foxidrive (Oct 20, 2012)

We can't test your command without being able to verify the value - but the error message also states that the value may not be there. 

Does the value have double backslashes?

Are those double quote in your message the ones you are using - because they are not normal quotes.


----------



## virtualwolf (Feb 22, 2016)

Thanks for the reply foxidrive. When you look at the value in regedit it does not have the double slashes. It has single slashes, but when the key is exported it has double slashes. The reason I added it to the batch file like that is that I did some research and found a post from McAfee that would instruct people to place these lines in a batch file:
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\McAfee\\ePolicy Orchestrator\\" /f

REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\\WINDOWS\\Installer\\{474A7C22-C823-401B-A52C-26D876957E5E}\\" /f

I've tried it the following ways:
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders" /v "C:\Program Files\UltraVNC" /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\\Program Files\\UltraVNC\\"="" /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\\Program Files\\UltraVNC" /f>nul
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC" /f
REM REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC\"="" /f

On this one I get "ERROR: Invalid Syntax.". I would suspect because of no quotes around the C:\.....:
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v C:\Program Files\UltraVNC /f 

It's really kind of strange. I've got all kinds of other lines of code to delete registry keys and they work. This one does not. Everything else related to UltraVNC seems to be gone from the computer too. I think I made some progress while replying to this post. If I run this line manually from an elevated command prompt I get prompted for Y or N to delete:
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC\"=""/f

After it runs is says this:
Delete the registry value C:\Program Files\UltraVNC"="/f (Yes/No)?

I tried to run it again in a batch file, but I still get prompted and need it to run silently. So I guess I'm still looking for help on that part. Thanks


----------



## virtualwolf (Feb 22, 2016)

Even if I choose Y to delete the key still remains. The only way to get it deleted is to manually right click and choose delete. Then it goes away. I would like to know if there is a known issue deleting keys from the path below or not:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders


----------



## foxidrive (Oct 20, 2012)

Try this: the value itself is the term to specify.


```
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC"/f
```


----------



## virtualwolf (Feb 22, 2016)

Thanks for the response foxidrive. When I run that it says:
Delete the registry value C:\Program Files\UltraVNC"="/f (Yes/No)?

When I press y and hit enter it says:
ERROR: The system was unable to find the specified registry key or value.

It's really strange. I think I will just have our GPO guy delete it with a GPO, but I would still like to understand why it doesn't work. Thanks again for the help.


----------



## foxidrive (Oct 20, 2012)

I made a typing error and didn't put a space before the /f

Try this: the ="" part isn't meant to be in the command.


```
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC" /f
```


----------



## virtualwolf (Feb 22, 2016)

That gives this error:
ERROR: The system was unable to find the specified registry key or value.

I think that is the same line of code I tried when I posted the second time....4th one down. I tried this:
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC\" /f

Then it says:
Delete the registry value C:\Program Files\UltraVNC"="/f (Yes/No)?

If I type either Y or Yes it says this:
ERROR: The system was unable to find the specified registry key or value.

It's crazy. I double checked the path and it's correct. I mean if it prompts me for Yes or No it should already be able to see the path. Thanks alot for trying.


----------



## foxidrive (Oct 20, 2012)

virtualwolf said:


> I tried this:
> REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC\" /f
> 
> Then it says:
> Delete the registry value C:\Program Files\UltraVNC"="/f (Yes/No)?


That line you show above can't possibly give the result below it. The part =" is not in the command at all.

There's a backslash on the UltraVNC\ too which is different.



> virtualwolf said:
> 
> 
> > That gives this error:
> > ERROR: The system was unable to find the specified registry key or value.


To debug that message you will have to verify that the key exists, which is likely, but the value may not be there or is it subtly different in some way.


----------



## foxidrive (Oct 20, 2012)

Here's some code for you to test and verify the process. 
It uses a value called "C:\Program Files\UltraVNC-test"


```
@echo off
echo ======== adding key
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC-test"
echo ======== querying key
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC-test"
echo ======== deleting key
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC-test" /f
echo ======== querying key again
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders /v "C:\Program Files\UltraVNC-test"
pause
```
You may need to run the batch as administrator.


----------



## Rollin_Again (Sep 4, 2003)

As mentioned in the previous post try right clicking the batch file and choosing the option to "Run As Administrator"


----------

