markbeaker
Goto Top

Java via Loginscript deinstallieren

Hallo zusammen,

da Java ab nächstem Jahr Lizenzpflichtig wird, möchte ich in einer Windows Domaine alle Java Versionen von den Clients entfernen.
Ich hab bereits ein VBScript gebaut, wo ich mir den package - code aus der Registry auslese für Java und dann über die msiexe deinstalliere.

Leider funktioniert das ganze nicht so zuverlässig.
Hat jemand von euch damit schon Erfahrung, mit diesem Thema?

Gruß
Christian


If Not WScript.Arguments.Named.Exists("elevate") Then  
  CreateObject("Shell.Application").ShellExecute WScript.FullName _  
    , """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1  
  WScript.Quit
End If

On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
Set WSHShell = CreateObject("WScript.Shell")  
Set oShell = WScript.CreateObject("WScript.Shell")  
Set fsoLog = createObject("Scripting.FileSystemObject")  
Set logFile = fsoLog.openTextFile(javas.log", 8, true)  

Set objNet = CreateObject("WScript.Network")  
strCompName = objNet.ComputerName



strComputer = "."  


Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _  
    strComputer & "\root\default:StdRegProv")  

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"  
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys


For Each subkey In arrSubKeys
	value = WSHShell.RegRead( "HKEY_LOCAL_MACHINE" & "\" & strKeyPath & "\" & subkey & "\" & "DisplayName" )  
	If InStr(value, "Java") Then  
		UninstallValue = WSHShell.RegRead( "HKEY_LOCAL_MACHINE" & "\" & strKeyPath & "\" & subkey & "\" & "UninstallString" )  
		command = "cmd /c start /wait " & UninstallValue & " /qn /norestart"  
		'WScript.Echo command, DontShowWindow, WaitUntilFinished  
		oShell.Run command, DontShowWindow, WaitUntilFinished
	End If
Next

For Each subkey In arrSubKeys
	Checkvalue = WSHShell.RegRead( "HKEY_LOCAL_MACHINE" & "\" & strKeyPath & "\" & subkey & "\" & "DisplayName" )  
	If InStr(Checkvalue, "Java") Then  
		logFile.writeLine strCompName & ";ERROR;more Java found;" & command  
		WScript.Echo strCompName & ";ERROR;more Java found;" & command  
		Else
		logFile.writeLine strCompName & ";OK;Unistall no Java found;" & command  
		WScript.Echo strCompName & ";OK;Unistall, no Java found;" & command  
		WScript.Quit
	End If
Next

Content-ID: 394167

Url: https://administrator.de/contentid/394167

Printed on: December 2, 2024 at 14:12 o'clock

SlainteMhath
SlainteMhath Nov 29, 2018 at 09:08:18 (UTC)
Goto Top
Moin,

haben denn die User das Recht Software zu deinstallieren?

lg,
Slainte
MarkBeaker
MarkBeaker Nov 29, 2018 at 09:23:30 (UTC)
Goto Top
Moin,

ja dafür hab ich extra die Prüfung eingebaut, bzw. via Startup oder Shutdown Script getestet. Da sollten ja Systemrechte vorhanden sein.

Gruß
jsysde
Solution jsysde Nov 29, 2018 at 09:23:31 (UTC)
Goto Top
Moin.

Ich nehm' dafür nen WMI-Call:
wmic product where "Name like '%%JAVA%%'" call uninstall  

Das putzt alles, was irgendwie JAVA heisst, vom Rechner - benötigt aber entsprechende Rechte, als normaler User keine Chance.

Cheers,
jsysde
MarkBeaker
MarkBeaker Nov 29, 2018 at 11:52:22 (UTC)
Goto Top
Hallo jsysde,

werde das gleich mal testen. Ich melde mich mit dem Ergebniss.

Gruß
MarkBeaker
MarkBeaker Nov 30, 2018 at 10:54:58 (UTC)
Goto Top
Hallo,

hab es nun mit folgendem Script gelöst:

If Not WScript.Arguments.Named.Exists("elevate") Then  
  CreateObject("Shell.Application").ShellExecute WScript.FullName _  
    , """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1  
  WScript.Quit
End If
On Error Resume Next
const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
Set WSHShell = CreateObject("WScript.Shell")  
Set oShell = WScript.CreateObject("WScript.Shell")  
Set fsoLog = createObject("Scripting.FileSystemObject")  
Set logFile = fsoLog.openTextFile("javas.log", 8, true)  


Set Shell = CreateObject("WScript.Shell")  
	if Instance = "Java" then  
		Shell.Run "taskkill /F /IM java.exe",0,true  
		Shell.Run "taskkill /F /IM javaw.exe",0,true 'java without console  
		Shell.Run "taskkill /F /IM jp2launcher.exe",0,true  
		Shell.Run "taskkill /F /IM jqs.exe",0,true  'java quick starter  
		Shell.Run "taskkill /F /IM justed.exe",0,true ' java update  
	else
		Shell.Run  "taskkill /F /IM " & Instance,0,true  
	end if
Set Shell = Nothing

Set Shell = WScript.CreateObject("WScript.Shell")  
Shell.Run "taskkill /F /IM iexplore.exe",0,true  
Shell.Run "taskkill /F /IM firefox.exe",0,true  
Shell.Run "taskkill /F /IM chrome.exe",0,true  
Set Shell = Nothing


Set objNet = CreateObject("WScript.Network")  
strCompName = objNet.ComputerName

strComputer = "."  
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")  
Set colItems = objWMIService.ExecQuery( _
	"SELECT IdentifyingNumber FROM Win32_Product where Name Like '%%JAVA%%'",,48)  
	logFile.writeLine strCompName & ";START;"  
	
For Each objItem in colItems
	If objItem.Name = " " Then  
		logFile.writeLine strCompName & ";NO JAVA;"  
	Else
		Wscript.Echo "Folgende Installation gefunden, " & objItem.Name &" "& objItem.IdentifyingNumber  
		command = "cmd /c start /W MsiExec.exe /x " & objItem.IdentifyingNumber & " /qn /norestart"  
		Wscript.Echo command
		oShell.Run command, DontShowWindow, WaitUntilFinished
		logFile.writeLine strCompName & ";UNINST;"& objItem.Name & ";" & objItem.IdentifyingNumber	  
	End If
Next


Set checkcolItems = objWMIService.ExecQuery( _
	"SELECT IdentifyingNumber FROM Win32_Product where Name Like '%%JAVA%%'",,48)  
For Each checkobjItem in checkcolItems
	If checkobjItem.Name = " " Then  
		logFile.writeLine strCompName & ";OK;"  
	Else
		logFile.writeLine strCompName & ";ERROR;"& checkobjItem.Name & ";" & checkobjItem.IdentifyingNumber	  
	End If
Next
logFile.writeLine strCompName & ";END;"