'Actually connect to the WMI service using the SWbemLocator and the SWbemContext parameters.I too had a need to perform this task. Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
ObjWbemContext.Add "_RequiredArchitecture", true ObjWbemContext.Add "_ProviderArchitecture", objProcessor.AddressWidth Set objWbemContext = CreateObject("WbemScripting.SWbemNamedValueSet") 'Provides the bitness context parameters for registry calls. 'Essentially this transparent redirection would hide 64bit Java runtimes from a script running in 32bit mode on a 64bit OS. 'Wow6432Node branch for every registry call to HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall. Without this the actual registry paths will be transparently redirected to the 'The following SWbem setup allows a script running in a x86 context, such as under the SCCM client, on a 圆4 system Set objWSHShell = CreateObject("WScript.Shell") '-Functions-įunction RemoveJava(strRegistryPath, aryVersions, strLogFilePath, objProcessor)ĭim objWSHShell, objRegistry, objWbemContext, objSWbemLocator, objSWbemServicesĭim strUninstallKey, strDisplayName, strUninstallString, strVersion RemoveJava "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", aryVersionsx86On圆4, strLogFilePath, objProcessor If (objProcessor.AddressWidth = "64") Then 'This call will remove x86 versions on a 圆4 system. RemoveJava "Software\Microsoft\Windows\CurrentVersion\Uninstall\", aryVersions, strLogFilePath, objProcessor 'This call will remove 圆4 versions on a 圆4 system and x86 versions on a x86 system. WScript.Echo vbCrLf & "Java uninstall script finished at " & Now() WScript.Echo "Finished problematic process check." WScript.Echo "Error Description: " & Err.Description WScript.Echo "Error Number: " & Err.Number WScript.Echo "Could not kill process " & objProcess.Name & "! Aborting Script!" WScript.Echo "Process " & objProcess.Name & " already closed." WScript.Echo "Killed process " & objProcess.Name & "." WScript.Echo "Found process " & objProcess.Name & "." 'Cycle through found problematic processes and kill them. 'Set this to look for errors that aren't fatal when killing processes. WScript.Echo "Checking for problematic processes." Set colProcesses = objWMIService.ExecQuery("Select Name from Win32_Process Where Name = 'jqs.exe' OR Name = 'jusched.exe' OR Name = 'jucheck.exe' OR Name = 'jp2launcher.exe' OR Name = 'java.exe' OR Name = 'javaws.exe' OR Name = 'javaw.exe'", "WQL", 48) 'Kill processes that might prevent installs or uninstalls. Set objProcessor = GetObject("winmgmts:\\.\root\cimv2:Win32_Processor='cpu0'") Check objProcessor.AddressWidth = "32" or "64" objProcessor.AddressWidth will give us bitness. Start /wait "" REGEDIT /E c:\temp\registry.tmp HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall