Repository navigation
[java_runtime_nuker.bat] WMIC no longer exists in the latest versions of Windows 11 #15
Copy link
Copy link
Open
Description
Activity
Good find, I know they'd planned on deprecating it for quite a while now, but didn't know it'd actually happened. More than likely the whole script will have to be re-written in PowerShell, unfortunately.
While I still need to vet this, I was able to convert it using Gemini and Copilot for testing. Nice template to start from and tested removal on some of my devices and it looks good so far.
update 10/26/25 with more regkeys and fixed a few functions.
[bool]$ForceCloseProcesses = $true [int]$ForceCloseProcessesExitCode = 1618 [string]$LogPath = "$env:SystemDrive\Windows\Logs" #region PREP AND CHECKS $ScriptVersion = "1.9.3 (PowerShell v1.0)" $ScriptUpdated = "2024-09-25" $CurDate = Get-Date -Format "yyyy-MM-dd" $LogFile = Join-Path -Path $LogPath -ChildPath "${env:COMPUTERNAME}_java_runtime_removal.log" $Host.UI.RawUI.WindowTitle = "Java Runtime Nuker v$ScriptVersion ($ScriptUpdated)" # Create a logging function function Write-Log { param([string]$Message) $logLine = "[{0}] {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message $logLine | Out-File -FilePath $LogFile -Append Write-Host $logLine } # Create log directory and clear previous log if (-not (Test-Path -Path $LogPath)) { New-Item -Path $LogPath -ItemType Directory -Force | Out-Null } if (Test-Path -Path $LogFile) { Remove-Item -Path $LogFile -Force } Write-Log "Java Runtime Nuker v$ScriptVersion ($ScriptUpdated)" Write-Log "Beginning removal of Java Runtime Environments (series 3-11, x86 and x64) and JavaFX..." # Check WMI/CIM service try { Get-CimInstance -ClassName Win32_TimeZone -ErrorAction Stop | Out-Null } catch { Write-Log "! WMI/CIM service appears to be broken. This script cannot continue without it." Write-Log "! Please repair the WMI repository manually and re-run." # The original script had a complex repair sequence. It's safer to advise manual repair in PowerShell. # For automation, one could translate the repair logic here, but it's risky. exit 1 } #endregion #region FORCE-CLOSE PROCESSES $processesToKill = @( "java", "javaw", "javaws", "jqs", "jusched", "jp2launcher", "iexplore", "iexplorer", "firefox", "chrome", "palemoon", "opera" ) if ($ForceCloseProcesses) { Write-Log "Looking for and closing all running browsers and Java instances..." $processesToKill | ForEach-Object { Write-Log "Searching for $_.exe..." Get-Process -Name $_ -ErrorAction SilentlyContinue | Stop-Process -Force } } else { Write-Log "Variable FORCE_CLOSE_PROCESSES is set to '$ForceCloseProcesses'. Checking for running processes before execution." $runningProcesses = Get-Process -Name $processesToKill -ErrorAction SilentlyContinue if ($null -ne $runningProcesses) { $runningProcesses | ForEach-Object { Write-Log "! ERROR: Process '$($_.ProcessName)' is currently running, aborting." } exit $ForceCloseProcessesExitCode } Write-Log "All clear, no running processes found. Going ahead with removal..." } #endregion #region UNINSTALLER SECTION Write-Log "Targeting individual JRE versions via WMI/CIM..." Write-Log "This might take a few minutes. Don't close this window." function Uninstall-Product { [CmdletBinding(SupportsShouldProcess)] param([string]$Filter) try { $products = Get-CimInstance -ClassName Win32_Product -Filter $Filter -ErrorAction Stop foreach ($product in $products) { Write-Log "Uninstalling: $($product.Name) (Version: $($product.Version))" if ($PSCmdlet.ShouldProcess($product.Name, "Uninstall")) { $result = $product | Invoke-CimMethod -MethodName Uninstall if ($result.ReturnValue -ne 0) { Write-Log "! Failed to uninstall $($product.Name). Return code: $($result.ReturnValue)" } } } } catch { # This is normal if no product matches the filter } } # JRE 11 Write-Log "JRE 11..." Uninstall-Product -Filter "Name LIKE 'Java 11%'" # JRE 10 Write-Log "JRE 10..." Uninstall-Product -Filter "IdentifyingNumber = '{EECB2736-D013-5AC5-9917-7656712F6931}'" Uninstall-Product -Filter "Name LIKE 'Java 10%'" # JRE 9 Write-Log "JRE 9..." Uninstall-Product -Filter "IdentifyingNumber = '{DA69628A-2608-5BA9-8749-1EE90CB29D95}'" Uninstall-Product -Filter "IdentifyingNumber = '{2590B9D6-4310-52BC-808E-1A585861A836}'" Uninstall-Product -Filter "IdentifyingNumber = '{885A3911-0760-5252-92C2-001B92997DEA}'" Uninstall-Product -Filter "Name LIKE 'Java 9%'" # JRE 8 Write-Log "JRE 8..." Uninstall-Product -Filter "IdentifyingNumber LIKE '{26A24AE4-039D-4CA4-87B4-2F8__180__F_}'" Uninstall-Product -Filter "IdentifyingNumber LIKE '{71_24AE4-039E-4CA4-87B4-2F64180__1F0}'" Uninstall-Product -Filter "IdentifyingNumber LIKE '{71_24AE4-039E-4CA4-87B4-2F32180__1F0}'" Uninstall-Product -Filter "IdentifyingNumber LIKE '{26A24AE4-039D-4CA4-87B4-2F__180___F_}'" # For versions > 99 Uninstall-Product -Filter "Name LIKE 'Java 8%'" # JRE 7 Write-Log "JRE 7..." Uninstall-Product -Filter "IdentifyingNumber LIKE '{26A24AE4-039D-4CA4-87B4-2F___170__FF}'" # JRE 6 Write-Log "JRE 6..." Uninstall-Product -Filter "IdentifyingNumber LIKE '{26A24AE4-039D-4CA4-87B4-2F8__160__FF}'" # Updates 23+ Uninstall-Product -Filter "IdentifyingNumber LIKE '{3248F0A8-6813-11D6-A77B-00B0D0160__0}'" # Updates 1-22 # JRE 5 Write-Log "JRE 5..." Uninstall-Product -Filter "IdentifyingNumber LIKE '{3248F0A8-6813-11D6-A77B-00B0D0150__0}'" # JRE 4 Write-Log "JRE 4..." Uninstall-Product -Filter "IdentifyingNumber LIKE '{7148F0A8-6813-11D6-A77B-00B0D0142__0}'" # JRE 3 (very old, uses IsUninst.exe) Write-Log "JRE 3 (AKA Java 2 Runtime v1.3.xx)..." $isUninst = Join-Path $env:SystemRoot "IsUninst.exe" if (Test-Path $isUninst) { $pfPaths = @($env:ProgramFiles, $env:ProgramFilesX86) | Where-Object { -not [string]::IsNullOrEmpty($_) } | Get-Unique foreach ($pfPath in $pfPaths) { # Loop for versions 1.3.1_01 to 1.3.1_25 1..25 | ForEach-Object { $version = $_.ToString("00") $uninstFile = Join-Path $pfPath "JavaSoft\JRE\1.3.1_$version\Uninst.isu" if (Test-Path $uninstFile) { Write-Log "Running uninstaller for JRE 1.3.1_$version..." Start-Process -FilePath $isUninst -ArgumentList "-f `"$uninstFile`" -a" -Wait -NoNewWindow } } # Version 1.3 $uninstFile13 = Join-Path $pfPath "JavaSoft\JRE\1.3\Uninst.isu" if (Test-Path $uninstFile13) { Write-Log "Running uninstaller for JRE 1.3..." Start-Process -FilePath $isUninst -ArgumentList "-f `"$uninstFile13`" -a" -Wait -NoNewWindow } } } # Wildcard uninstallers Write-Log "Specific targeting done. Now running WMIC/CIM wildcard catchall uninstallation..." Uninstall-Product -Filter "Name LIKE '%J2SE Runtime%'" Uninstall-Product -Filter "Name LIKE 'Java%Runtime%'" Uninstall-Product -Filter "Name LIKE 'Java%Update%'" Uninstall-Product -Filter "Name LIKE 'JavaFX%'" Write-Log "Done." #endregion #region REGISTRY CLEANUP Write-Log "Commencing registry cleanup..." #region PRE-DELETE # Sometimes the JRE uninstallers will fail if they can't find some files; deleting the reg keys seems to resolve it. # Thanks to u/GoogleDrummer for this section. Write-Log "Performing pre-delete registry cleanup for JRE 8 uninstallers..." try { $productKeyPath = "Registry::HKEY_CLASSES_ROOT\Installer\Products" Get-ChildItem -Path $productKeyPath -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*4EA42A62*" } | ForEach-Object { Write-Log "Removing problematic installer key: $($_.PSPath)" if ($PSCmdlet.ShouldProcess($_.PSPath, "Remove Registry Key")) { Remove-Item -Path $_.PSPath -Recurse -Force } } } catch { Write-Log "Could not perform pre-delete registry cleanup. This may be normal if the keys don't exist. Error: $($_.Exception.Message)" } #endregion $regSearchPaths = @( "HKLM:\SOFTWARE\Classes\Installer\Products", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ) $regSearchTerms = @( "J2SE Runtime", "Java(TM) 6 Update", "Java 7", "Java 8", "Java*Runtime" ) # Standard Uninstall search foreach ($regPath in $regSearchPaths) { if (Test-Path $regPath) { Write-Log "Searching $regpath for Java-related keys..." Get-ChildItem -Path $regPath | ForEach-Object { foreach ($term in $regSearchTerms) { try { $item = Get-ItemProperty -Path $key -ErrorAction Ignore if ($item.DisplayName -and $item.DisplayName -like "$term*") { write-log "Found $term in $regpath" write-log "delete key $regpath\$($item.PSChildName)" try { Remove-Item -Path "$regpath\$($item.PSChildName)" -Recurse -Force -ErrorAction Stop Write-Log "Successfully removed key $regpath\$($item.PSChildName)" } catch { Write-Log "Failed to remove key $regpath\$($item.PSChildName). Error: $($_.Exception.Message)" } } $null = $item } catch {} } } } } # UserData Installer search $userDataPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData" if (Test-Path $userDataPath) { Write-Log "Searching $userDataPath for Java-related keys..." # Get user SIDs Get-ChildItem -Path $userDataPath | ForEach-Object { $userSidKey = $_ $productsPath = Join-Path $userSidKey.PSPath "Products" if (Test-Path $productsPath) { # Get product GUIDs under the user's profile Get-ChildItem -Path $productsPath | ForEach-Object { $productKey = $_ $installPropertiesPath = Join-Path $productKey.PSPath "InstallProperties" if (Test-Path $installPropertiesPath) { try { $properties = Get-ItemProperty -Path $installPropertiesPath -Name DisplayName -ErrorAction SilentlyContinue if ($properties.DisplayName) { foreach ($term in $regSearchTerms) { if ($properties.DisplayName -like "$term*") { Write-Log "Found matching UserData key: $($properties.DisplayName)" Write-Log "Attempting to remove key: $($productKey.PSPath)" try { Remove-Item -Path $productKey.PSPath -Recurse -Force -ErrorAction Stop Write-Log "Successfully removed UserData key." # Break the inner loop since the key is now gone break } catch { Write-Log "Failed to remove UserData key $($productKey.PSPath). Error: $($_.Exception.Message)" } } } } } catch {} } } } } } # Delete specific known Java keys Write-Log "Purging other known Java registry locations..." $knownKeys = @( "HKLM:\SOFTWARE\Wow6432Node\JavaSoft", "HKLM:\SOFTWARE\Wow6432Node\JreMetrics", "HKLM:\SOFTWARE\JavaSoft", "HKLM:\SOFTWARE\JreMetrics", # Control Panel Icons "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\{4299124F-F2C3-41b4-9C73-9236B2AD0E8F}", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\explorer\ControlPanelWOW64\NameSpace\{4299124F-F2C3-41b4-9C73-9236B2AD0E8F}" ) foreach ($key in $knownKeys) { if (Test-Path -Path "Registry::$key") { Write-Log "Removing key: $key" if ($PSCmdlet.ShouldProcess($key, "Remove Registry Key")) { Remove-Item -Path "Registry::$key" -Recurse -Force -ErrorAction SilentlyContinue } } } Write-Log "Registry cleanup done." #endregion #region FILE AND DIRECTORY CLEANUP Write-Log "Commencing file and directory cleanup..." # Remove scheduled tasks Write-Log "Removing Java tasks from the Windows Task Scheduler..." Get-ScheduledTask -TaskPath "\" -TaskName "Java*" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$false # Remove services Write-Log "Removing Java services..." Get-Service -Name "JavaQuickStarterService", "jusched" -ErrorAction SilentlyContinue | ForEach-Object { Write-Log "Stopping and removing service: $($_.Name)" if ($PSCmdlet.ShouldProcess($_.Name, "Stop and Remove Service")) { Stop-Service -Name $_.Name -Force -ErrorAction SilentlyContinue # sc.exe delete is more reliable for immediate removal sc.exe delete $_.Name } } # Remove leftover binaries from system folders Write-Log "Finding and removing leftover Java exe files from system folders..." $systemFiles = @( Join-Path $env:WINDIR "System32\java.exe" Join-Path $env:WINDIR "System32\javaw.exe" Join-Path $env:WINDIR "System32\javaws.exe" Join-Path $env:WINDIR "SysWOW64\java.exe" Join-Path $env:WINDIR "SysWOW64\javaw.exe" Join-Path $env:WINDIR "SysWOW64\javaws.exe" ) $systemFiles | ForEach-Object { if (Test-Path $_) { Write-Log "Removing file: $_" Remove-Item -Path $_ -Force -ErrorAction SilentlyContinue } } # Nuke installation directories Write-Log "Removing Java installation directories..." $programFilesPaths = @($env:ProgramFiles, $env:ProgramFilesX86) | Where-Object { -not [string]::IsNullOrEmpty($_) } | Get-Unique foreach ($pfPath in $programFilesPaths) { $javaPath = Join-Path $pfPath "Java" if (Test-Path $javaPath) { Write-Log "Removing contents of $javaPath" Get-ChildItem -Path $javaPath -Directory -Filter "jre*" -Recurse | Remove-Item -Recurse -Force Get-ChildItem -Path $javaPath -Directory -Filter "j2re*" -Recurse | Remove-Item -Recurse -Force Remove-Item -Path $javaPath -Recurse -Force -ErrorAction SilentlyContinue } $javaSoftPath = Join-Path $pfPath "JavaSoft\JRE" if (Test-Path $javaSoftPath) { Write-Log "Removing $javaSoftPath" Remove-Item -Path $javaSoftPath -Recurse -Force } $oracleCommonPath = Join-Path $pfPath "Common Files\Oracle\Java" if (Test-Path $oracleCommonPath) { Write-Log "Removing $oracleCommonPath" Remove-Item -Path $oracleCommonPath -Recurse -Force } } # Nuke Java Update directory Write-Log "Removing Java Update directories..." $commonPFPaths = @($env:CommonProgramFiles, ${env:CommonProgramFiles(x86)}) | Where-Object { -not [string]::IsNullOrEmpty($_) } | Get-Unique foreach ($cpfPath in $commonPFPaths) { $javaUpdatePath = Join-Path $cpfPath "Java\Java Update" if (Test-Path $javaUpdatePath) { Remove-Item -Path $javaUpdatePath -Recurse -Force } } # Nuke Java installer cache from user profiles Write-Log "Purging Java installer cache from user profiles..." Get-ChildItem -Path (Join-Path $env:SystemDrive "Users") -Directory | ForEach-Object { $userProfile = $_.FullName $sunJavaCache = Join-Path $userProfile "AppData\LocalLow\Sun\Java" if (Test-Path $sunJavaCache) { Write-Log "Removing cache for user $($_.Name): $sunJavaCache" Remove-Item -Path $sunJavaCache -Recurse -Force -ErrorAction SilentlyContinue } } # Miscellaneous cleanup Write-Log "Searching for and purging other Java Runtime-related directories..." $miscPaths = @( Join-Path $env:ProgramData "Oracle\Java" Join-Path $env:ProgramData "Microsoft\Windows\Start Menu\Programs\Java" ) $miscPaths | ForEach-Object { if (Test-Path $_) { Write-Log "Removing: $_" Remove-Item -Path $_ -Recurse -Force } } Write-Log "File and directory cleanup done." #endregion #region FINALIZATION Write-Log "Log file: `"$LogFile`"" Write-Log "COMPLETE. Recommend rebooting and washing your hands." # Return exit code 0 for success exit 0 #endregion
Metadata
Metadata
Assignees
Labels
No labels
Hello !
Following the latest Windows 11 updates, WMIC no longer exists, so the file “%WINDIR%\system32\wbem\wmic.exe” no longer exists.
Is it possible to change this?
Or even replace the wmic.exe with the new PowerShell-based system for computers that no longer have a wmic.exe?
=> https://learn.microsoft.com/powershell/scripting/learn/ps101/07-working-with-wmi
Thanks a lot!
Lusiiky