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?
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)
The script has too many errors and needs to be fixed.
Community Chosen Answer
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.