# Help cleaning up batch file.



## JrSysEngineer (Mar 23, 2012)

I am having the same kind of issue as the person was in the thread below:

http://forums.techguy.org/dos-other/906078-solved-adobe-batch-help.html

I have created a batch script that will search for and uninstall all versions of Java. I would like to clean it up, like the person from the above thread did with Adobe, so that I do not have to list every registry key from Java 6 Update 14 through Java 6 update 31. There are only 2 characters in the key that change from one platform to the other (x86 to x64) and 2 characters that change from one update to the next. I tried to adapt the code from the referenced thread to suit what i wanted to do but it would not work. My current Batch script is provided below.


```
ECHO OFF
CLS


ECHO. *******************************************************
ECHO. *******************************************************
ECHO.
ECHO.              DO NOT CLOSE THIS WINDOW
ECHO. 
ECHO. Installing Java 7 Update 3
ECHO. 
ECHO. Do not close this window. This window will close
ECHO. automatically when the installation is complete. 
ECHO.
ECHO. *******************************************************
ECHO. *******************************************************



::Variables
SET JAVAINSTALL1="C:\Radia\Custom\20120200\x86\jre1.7.0_03.msi"
SET JAVAINSTALL2="C:\Radia\Custom\20120200\x64\jre1.7.0_03.msi"
SET JAVAREGISTRY="HKLM\SOFTWARE\JavaSoft\Java Plug-in\1.7.0_03"



::Checks to see if Java 6 X86 is installed: If yes, uninstall Java 6. If no, install Java 7
IF EXIST "C:\Program Files (x86)\Java\jre6" ( 
GOTO REMOVEJRE6X86
) ELSE (
GOTO JAVAx64CHECK
)



::Uninstall Java 6 x86 All Versions
:REMOVEJRE6X86
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216014FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216014FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216015FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216015FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216016FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216016FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216017FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216017FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216018FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216018FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216019FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216019FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216020FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216020FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216021FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216021FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216022FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216022FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216023FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216023FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216024FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216024FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216026FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216026FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216029FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216029FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216030FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216030FF}
Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F83216031FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F83216031FF}



::Checks to see if Java 6 X64 is installed: If yes, uninstall Java 6. If no, install Java 7
:JAVAx64CHECK
IF EXIST "C:\Program Files\Java\jre6" ( 
GOTO REMOVEJRE6X64
) ELSE (
GOTO INSTALLJAVA7X86
)



::Uninstall Java 6 x64 All Versions
:REMOVEJRE6X64
Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F86416021FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F86416021FF}
Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F86416022FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F86416022FF}
Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F86416023FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F86416023FF}
Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F86416024FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F86416024FF}
Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F86416026FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F86416026FF}
Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F86416029FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F86416029FF}
Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F86416030FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F86416030FF}
Reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /v {26A24AE4-039D-4CA4-87B4-2F86416031FF} 1>nul 2>nul
if errorlevel=0 start /wait MsiExec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F86416031FF}



GOTO INSTALLJAVA7X86



::Install Java 7 Update 3 X86
:INSTALLJAVA7X86
START /WAIT msiexec /qn /i %JAVAINSTALL1%
GOTO INSTALLJAVA7X64
)



::Install Java 7 Update 3 X64
:INSTALLJAVA7X64
START /WAIT msiexec /qn /i %JAVAINSTALL2%
GOTO EXIT
)



::Terminate Installation
:EXIT
EXIT
```
Ideally I would like the script to search the registry for the Java Key, regardless of the platform and update, if it is found run the uninstall registry value, then loop through the script again until the key is no longer found. If the Java Key is not found (java is not installed at all) I would like the script to skip down to the install section. My knowledge in scripting is limited so I'm not sure if this is possible to cover both the x64 and x86 platforms with the same code, but if is not two sections, one for x86 and one for x64, would be acceptable as well.

Sorry for the SUPER long first post but I have been searching for a solution for the past couple weeks.

Thanks for any help y'all may provide.


----------



## Squashman (Apr 4, 2003)

Looks like the guys at DosTips are helping you pretty well. They are much better than I am when it comes to batch files. I am not good with the registry stuff.


----------



## JrSysEngineer (Mar 23, 2012)

Yeah they are. I just want to get some more opinions on this as I can to help me figure this out. And since I found the thread I linked to I figured it wouldn't hurt to post this up here as well.


----------



## Squashman (Apr 4, 2003)

I don't know how Radia works personally but our company does use it. I am surprised their isn't some easy way to do this with Radia.


----------



## JrSysEngineer (Mar 23, 2012)

I wish I knew. We were given no training on Radia. From what I have been told from others we shouldn't even have to use batch files for this type of thing, but that is how the team members from the past have been doing things so that's how they trained us.


----------



## Squashman (Apr 4, 2003)

I know nothing about VBscript but this link looks pretty interesting.
http://www.itninja.com/question/silent-uninstall-java-all-versions


----------

