reg query problem. What am I doing wrong?
The code down below does not work. Text file is created but it is empty, so cmd window does not show anything.
Can anybody help me?
@echo off
reg query hklm\Software\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test /f "InstallLocation" /s >>"%temp%\uninst.txt"
for /f "delims=\ tokens=2" %%a in ('type "%temp%\uninst.txt"') do (echo %%a)
PAUSE
Answers (5)
The script has too many errors and needs to be fixed.
From what I can tell, you are trying to write a script that finds the command that needs to be run to uninstall a piece of software, and then it deletes all the directories associated with that program so it cleans up what is left over. Correct?
Problem is, you're script has wayyyy too many problems with it in order to work. For one, your FOR loops are executing directory names as commands due to using the TYPE command and using \ as a delimiter. Also, if the program does not have an UninstallString, it will still delete the directory even if it hasn't uninstalled, what if the uninstallation fails? It will still delete the directory (or attempt to).
I think you just need to deal with the fact that when you uninstall a program, that it leaves some stuff behind. You need to remember, some applications do this on purpose due to other programs using some of those DLL's and etc as dependencies. This script could create a very unstable environment.
I'd say you are better off running a script that will output the uninstall string into a text file which you can run manually. The other problem with this script, is, running the uninstall string will NOT run a silent uninstall. You will still need to be there to uninstall it. In the end, you are better off just manually uninstalling the command via the Add/Remove Programs menu in the control panel.
If you need to uninstall the program silently, I recommend using this site to see if someone already has a post on how to install/uninstall software silently and remotely. Most software can be uninstalled as long as you have the program ID and uninstall it with MSIEXEC. There are plenty of programs that will grab the program ID of installed software for you.
Hope this helps.
Comments:
-
Also, this is in reference to your updated script, not the original post. - chadbaldwin 11 years ago
-
I have to agree with Chad's assessment on this. You're trying to devise a one-shot solution for uninstalling applications that will have a variety of uninstall methods, be it msiexec commands or setups with parameters. A tough job that will be quite involved to get done right.. - pjgeutjens 11 years ago
I am stupid. Sorry. Now I changed it and it is not working.
@echo off
reg query hklm\Software\Microsoft\Windows\CurrentVersion\Uninstall\Test /v "UninstallString" /s >>"%temp%\uninst.txt"
reg query hklm\Software\Microsoft\Windows\CurrentVersion\Uninstall\Test /v "InstallLocation" /s >>"%temp%\location.txt"
for /f "delims=\ tokens=2" %%a in ('type "%temp%\uninst.txt"') do ("%%a")
for /f "delims=\ tokens=2" %%a in ('type "%temp%\location.txt"') do (rd /s /q "%%a")
PAUSE
'"Software"' is not recognized as an internal or external command,
operable program or batch file.
'"Program Files (x86)"' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the file specified.
The system cannot find the file specified.
Press any key to continue . . .