Hello.
About half a year or a year ago, I helped a person with a problem: he wanted to automatically remove everything that relates to Java from a computer running Windows.
For starters, I looked for the installer to have some key that will help to do this.
I do not remember exactly, it seems I did find it, but the functionality was broken, the installer did not perform the desired function.
With additional options, I used all kinds of VB solutions, or requiring .NET, like
JavaRa .
In the end, I stumbled upon a discussion in which I found one treasured line with the useful wmic command, and as a result, the solution of the problem degenerated into a very small batch file that uses only the system's tools to execute what the long scripts are written for.
The command is part of
WMI , and is present in Windows 2000 and above.
@echo off echo Making list of installed Java packages... Please wait. wmic product where "name like 'Java%%'" get IdentifyingNumber > "%TEMP%\deleteAllJava_1.txt" type "%TEMP%\deleteAllJava_1.txt" | findstr {........-....-....-....-............} > "%TEMP%\deleteAllJava_2.txt" if exist "%TEMP%\deleteAllJava_1.txt" del "%TEMP%\deleteAllJava_1.txt" echo Done. Changing directory... set VAR="%CD%" cd %TEMP% echo Done. Deleting Java packages... for /f "tokens=*" %%a in (deleteAllJava_2.txt) do ( echo Deleting package: %%a msiexec /x %%a /norestart /qb-! ) cd %VAR% echo Making list of installed Java 5 packages... Please wait. wmic product where "name like 'J2SE%%'" get IdentifyingNumber > "%TEMP%\deleteAllJava_1.txt" type "%TEMP%\deleteAllJava_1.txt" | findstr {........-....-....-....-............} > "%TEMP%\deleteAllJava_2.txt" if exist "%TEMP%\deleteAllJava_1.txt" del "%TEMP%\deleteAllJava_1.txt" echo Done. Changing directory... set VAR="%CD%" cd %TEMP% echo Done. Deleting Java packages... for /f "tokens=*" %%a in (deleteAllJava_2.txt) do ( echo Deleting package: %%a msiexec /x %%a /norestart /qb-! ) if exist "%TEMP%\deleteAllJava_2.txt" del "%TEMP%\deleteAllJava_2.txt" echo Done. Changing directory back... cd %VAR% echo Process completed sucessfully...
I think a little explanation does not hurt:
The first part removes all installations starting with “Java” (Java 6 and higher), the second part - “J2SE” (Java 5).
I don’t remember if it handles Java 4, but I don’t think it will be a problem to modify the batch file.
In each part, the file% TEMP% \ deleteAllJava_1.txt is formed, it will contain lines with product identifiers. Then, with the help of findstr, only the identifiers themselves are eliminated, the excess is removed. As a result, the file% TEMP% \ deleteAllJava_2.txt appears, and the first one is deleted. Then, using for, search through the lines from the second file launches the command to delete products by identifier (msiexec with the / x key).
Plus, the batch file must be started with administrator rights, then the UAC request will be made only once at startup, and not every time the package is uninstalled.
It is worth noting that if any other application starts with Java or J2SE, it will also fall under the knife, so I would be grateful if you tell me how to fix this script so that it does not break firewood.
Also useful comments on the work of the script are welcome, because I do not consider myself a master in writing .bat-files. ;)
Thank you, successful use!
UPD1 : A more elegant solution, but removes only when the command is run from the administrator. The variant above, launched not from the administrator, will at least prompt the user for permission (with UAC enabled), but for each installed product.
@echo off echo Removing installed packages of Java 5+... Please wait. wmic product where "name like 'Java%%' or name like 'J2SE%%'" call uninstall /nointeractive echo Process completed sucessfully...