Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
tigerweld
- Posts: 2
- Joined: 23 May 2013 08:46
#1
Post
by tigerweld » 23 May 2013 08:51
I have a script that uninstalls different versions of java and I would like to write each version it removes to a log file for future reference. (in case there is an app that uses a specific version and I need to reinstall it). Below is my script. I curently have
echo %%a >>c:\temp\JavaUninstall.txt
but it writes every line in the loop. i only want the one that it detects.
Code: Select all
For %%a in (
{7148F0A8-6813-11D6-A77B-00B0D0142000}
{7148F0A8-6813-11D6-A77B-00B0D0142010}
{7148F0A8-6813-11D6-A77B-00B0D0142020}
{7148F0A8-6813-11D6-A77B-00B0D0142030}
{7148F0A8-6813-11D6-A77B-00B0D0142040}
{7148F0A8-6813-11D6-A77B-00B0D0142050}
{7148F0A8-6813-11D6-A77B-00B0D0142060}
{7148F0A8-6813-11D6-A77B-00B0D0142070}
{7148F0A8-6813-11D6-A77B-00B0D0142080}
{7148F0A8-6813-11D6-A77B-00B0D0142090}
{7148F0A8-6813-11D6-A77B-00B0D0142100}
{7148F0A8-6813-11D6-A77B-00B0D0142110}
{7148F0A8-6813-11D6-A77B-00B0D0142120}
{7148F0A8-6813-11D6-A77B-00B0D0142130}
{7148F0A8-6813-11D6-A77B-00B0D0142140}
{7148F0A8-6813-11D6-A77B-00B0D0142150}
{7148F0A8-6813-11D6-A77B-00B0D0142160}
{3248F0A8-6813-11D6-A77B-00B0D0150000}
{3248F0A8-6813-11D6-A77B-00B0D0150010}
{3248F0A8-6813-11D6-A77B-00B0D0150020}
{3248F0A8-6813-11D6-A77B-00B0D0150030}
{3248F0A8-6813-11D6-A77B-00B0D0150040}
{3248F0A8-6813-11D6-A77B-00B0D0150050}
{3248F0A8-6813-11D6-A77B-00B0D0150060}
{3248F0A8-6813-11D6-A77B-00B0D0150070}
{3248F0A8-6813-11D6-A77B-00B0D0150080}
{3248F0A8-6813-11D6-A77B-00B0D0150090}
{3248F0A8-6813-11D6-A77B-00B0D0150100}
{3248F0A8-6813-11D6-A77B-00B0D0150110}
{3248F0A8-6813-11D6-A77B-00B0D0150120}
{3248F0A8-6813-11D6-A77B-00B0D0150130}
{3248F0A8-6813-11D6-A77B-00B0D0150140}
{26A24AE4-039D-4CA4-87B4-2F83216000FF}
{26A24AE4-039D-4CA4-87B4-2F83216010FF}
{26A24AE4-039D-4CA4-87B4-2F83216020FF}
{26A24AE4-039D-4CA4-87B4-2F83216030FF}
{26A24AE4-039D-4CA4-87B4-2F83216040FF}
{26A24AE4-039D-4CA4-87B4-2F83216050FF}
{26A24AE4-039D-4CA4-87B4-2F83216060FF}
{26A24AE4-039D-4CA4-87B4-2F83216070FF}
{26A24AE4-039D-4CA4-87B4-2F83216080FF}
{26A24AE4-039D-4CA4-87B4-2F83216090FF}
{26A24AE4-039D-4CA4-87B4-2F83216010FF}
{26A24AE4-039D-4CA4-87B4-2F83216011FF}
{26A24AE4-039D-4CA4-87B4-2F83216012FF}
{26A24AE4-039D-4CA4-87B4-2F83216013FF}
{26A24AE4-039D-4CA4-87B4-2F83216014FF}
{26A24AE4-039D-4CA4-87B4-2F83216015FF}
{26A24AE4-039D-4CA4-87B4-2F83216016FF}
{26A24AE4-039D-4CA4-87B4-2F83216017FF}
{26A24AE4-039D-4CA4-87B4-2F83216018FF}
{26A24AE4-039D-4CA4-87B4-2F83216019FF}
{26A24AE4-039D-4CA4-87B4-2F83216020FF}
{26A24AE4-039D-4CA4-87B4-2F83216021FF}
{26A24AE4-039D-4CA4-87B4-2F83216022FF}
{26A24AE4-039D-4CA4-87B4-2F83216023FF}
{26A24AE4-039D-4CA4-87B4-2F83216024FF}
{26A24AE4-039D-4CA4-87B4-2F83216026FF}
{26A24AE4-039D-4CA4-87B4-2F83216029FF}
{26A24AE4-039D-4CA4-87B4-2F83216030FF}
{26A24AE4-039D-4CA4-87B4-2F83216031FF}
) DO (
REG QUERY HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v %%a 1>nul 2>nul
echo %%a >>c:\temp\JavaUninstall.txt
IF errorlevel=0 start /wait MsiExec.exe /qn /x %%a
)
-
Endoro
- Posts: 244
- Joined: 27 Mar 2013 01:29
- Location: Bozen
#2
Post
by Endoro » 23 May 2013 10:29
try this:
Code: Select all
) DO (
REG QUERY HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v %%a 1>nul 2>nul && (
>>c:\temp\JavaUninstall.txt echo(%%a
start /wait MsiExec.exe /qn /x %%a
)
)
-
tigerweld
- Posts: 2
- Joined: 23 May 2013 08:46
#3
Post
by tigerweld » 23 May 2013 12:20
That didn't work. It kept the script from running entirely. Thanks though.
-
Endoro
- Posts: 244
- Joined: 27 Mar 2013 01:29
- Location: Bozen
#4
Post
by Endoro » 23 May 2013 14:59
it seems, %%a is not the key, it's part of the path. Example:
Code: Select all
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}
AuthorizedCDFPrefix REG_SZ
Comments REG_SZ
Contact REG_SZ
DisplayVersion REG_SZ 9.0.21022
HelpLink REG_SZ
HelpTelephone REG_SZ
InstallDate REG_SZ 20090319
InstallLocation REG_SZ
ModifyPath REG_EXPAND_SZ MsiExec.exe /X{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}
NoModify REG_DWORD 0x1
NoRepair REG_DWORD 0x1
Publisher REG_SZ Microsoft Corporation
Readme REG_SZ
Size REG_SZ
EstimatedSize REG_DWORD 0x2d6c
UninstallString REG_EXPAND_SZ MsiExec.exe /X{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}
URLInfoAbout REG_SZ
URLUpdateInfo REG_SZ
VersionMajor REG_DWORD 0x9
VersionMinor REG_DWORD 0x0
WindowsInstaller REG_DWORD 0x1
Version REG_DWORD 0x900521e
Language REG_DWORD 0x409
DisplayName REG_SZ Microsoft Visual C++ 2008 Redistributable - x86 9.0.21022
you can't ask with the "reg query /v" option for parts of a path, this returns always an error.
try this:
Code: Select all
) DO (
REG QUERY HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\%%a /v UninstallString 1>nul 2>nul && (
>>c:\temp\JavaUninstall.txt echo(%%a
start /wait MsiExec.exe /qn /x %%a
)
)
-
Aacini
- Expert
- Posts: 1932
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#5
Post
by Aacini » 23 May 2013 17:05
This is just a suggestion:
Code: Select all
for /L %%b in (0,1,9) do (
for %%a in (7148F0A8 3248F0A8) do (
call :Uninstall {%%a-6813-11D6-A77B-00B0D01420%%b0}
)
call :Uninstall {26A24AE4-039D-4CA4-87B4-2F832160%%b0FF}
)
for /L %%b in (10,1,16) do (
for %%a in (7148F0A8 3248F0A8) do (
call :Uninstall {%%a-6813-11D6-A77B-00B0D0142%%b0}
)
call :Uninstall {26A24AE4-039D-4CA4-87B4-2F832160%%bFF}
)
for /L %%b in (17,1,31) do (
call :Uninstall {26A24AE4-039D-4CA4-87B4-2F832160%%bFF}
)
. . .
:Uninstall
REG QUERY HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\%1 /v UninstallString 1>nul 2>nul
IF %errorlevel% == 0 (
echo %1 >>c:\temp\JavaUninstall.txt
start /wait MsiExec.exe /qn /x %1
)
exit /B
Yes, I know this program also check for some keys that are not present in the original list, but this doesn't matter if those versions are not installed.