/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (5)

Answer Summary:
The script has too many errors and needs to be fixed.
Posted by: chadbaldwin 11 years ago
Senior White Belt
3

 

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
Posted by: pjgeutjens 11 years ago
Red Belt
1
hklm\Software\SOFTWARE

One too many Software's that I can see for starters..

Posted by: pjgeutjens 11 years ago
Red Belt
1

Secondly

/f  "InstallLocation" 

I think that needs to be /v

Posted by: McRip 11 years ago
Orange Senior Belt
1

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 . . .
Posted by: pjgeutjens 11 years ago
Red Belt
1

I think the strings you're reading out of the registry keys might need to be surrounded by quotes to execute them, since they contain spaces

 

are your uninst.txt and location.txt files filling up correctly now?

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Link

Related Links

Post

Related Posts

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ