Seite 1 von 1

Registry Schleife Uninstall Strings

Verfasst: 26 Apr 2019, 14:45
von luca_de
Hallo zusammen,

ich möchte folgendes realisieren:
Mit einer Schleife alle Uninstall Strings von Java JRE finden und diese dann nutzen um alle Versionen zu deinstallieren.

Hat jemand eine Ahnung wie ich die Schleife machen kann? Momentan kann ich nur über folgendes die einzelnen Keys auslesen:

Code: Alles auswählen

getRegistryVarMap64("hklm\SOFTWARE\microsoft\windows\currentversion\uninstall\{xxxx}")

Re: Registry Schleife Uninstall Strings

Verfasst: 29 Apr 2019, 09:55
von SisterOfMercy
This is part of the delsub3264.opsiscript I use:

Code: Alles auswählen

DefStringList $result$
DefStringList $result1$
DefVar $appKey$
DefVar $UninstallCommandList$
DefVar $appString$
DefVar $appKeyString$
DefVar $testName$

Set $appKeyString$ = "DisplayName"
Set $appString$ = "Java Runtime"

if ($INST_SystemType$ = "x86 System") 
	set $UninstallCommandList$ = ""	
	Set $result$ = getRegistryKeyList32("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
	for $app$ in $result$ do Sub_searchApp32
	if not ($UninstallCommandList$ = "")
		set $result1$ = splitString($UninstallCommandList$,"::")
		for $UninstallCommand$ in $result1$ do Winbatch_uninstall_32 /32Bit
		sub_check_exitcode
	endif
	
	comment "Delete files"
	Files_uninstall_32 /32Bit
	Files_uninstall_AllProfiles /AllNtUserProfiles	
	comment "Cleanup registry"
	Registry_uninstall /32Bit
	Registry_uninstall_AllProfiles /AllNTUserDats
endif

if ($INST_SystemType$ = "64 Bit System") 
	set $UninstallCommandList$ = ""
	Set $result$ = getRegistryKeyList64("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
	for $app$ in $result$ do Sub_searchApp64
 	if not ($UninstallCommandList$ = "")
		set $result1$ = splitString($UninstallCommandList$,"::")
		for $UninstallCommand$ in $result1$ do Winbatch_uninstall_64 /64Bit
		sub_check_exitcode
	endif

	set $UninstallCommandList$ = ""
	Set $result$ = getRegistryKeyList32("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
	for $app$ in $result$ do Sub_searchApp32
	if not ($UninstallCommandList$ = "")
		set $result1$ = splitString($UninstallCommandList$,"::")
		for $UninstallCommand$ in $result1$ do Winbatch_uninstall_32 /32Bit
		sub_check_exitcode
	endif
	
	comment "Delete files"
	Files_uninstall_64 /64Bit
	Files_uninstall_AllProfiles /AllNtUserProfiles	
	comment "Cleanup registry"
	Registry_uninstall /64Bit
	Registry_uninstall_AllProfiles /AllNTUserDats
endif

comment "Delete program shortcuts"
LinkFolder_uninstall

[Winbatch_uninstall_32]
$UninstallCommand$

[Winbatch_uninstall_64]
$UninstallCommand$

[Winbatch_uninstall_msi_32]
"%SystemRoot%\system32\msiexec.exe" /x $MsiId32$ /qb-! /l*v "$LogDir$\$ProductId$-uninstall.log" REBOOT=ReallySuppress

[Winbatch_uninstall_msi_64]
"%SystemRoot%\system32\msiexec.exe" /x $MsiId64$ /qb-! /l*v "$LogDir$\$ProductId$-uninstall.log" REBOOT=ReallySuppress

[Files_uninstall_32]
; Example for recursively deleting the installation directory (don't forget the trailing backslash):
;
; delete -sf "$InstallDir32$\"

[Files_uninstall_64]
; Example for recursively deleting the installation directory (don't forget the trailing backslash):
;
; delete -sf "$InstallDir64$\"

[Files_uninstall_AllProfiles]
; delete -sf "%UserProfileDir%\Application Data\$ProductId$\"

[Registry_uninstall]
; Example of deleting a registry key:
;
; deletekey [HKEY_LOCAL_MACHINE\Software\$ProductId$]
;
; deletekey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$ProductId$]

[Registry_uninstall_AllProfiles]


[LinkFolder_uninstall]
; Example of deleting a folder from AllUsers startmenu:
;
; set_basefolder common_programs
; delete_subfolder $ProductId$
;
; Example of deleting a shortcut from AllUsers desktop:
;
; set_basefolder common_desktopdirectory
; set_subfolder ""
; delete_element $ProductId$
;
; Example of deleting a shortcut from AllUsers startmenu:
;
; set_basefolder common_programs
; set_subfolder ""
; delete_element $ProductId$

[Sub_check_exitcode]
comment "Test for installation success via exit code"
set $ExitCode$ = getLastExitCode
; informations to exit codes see
; http://msdn.microsoft.com/en-us/library/aa372835(VS.85).aspx
; http://msdn.microsoft.com/en-us/library/aa368542.aspx
if ($ExitCode$ = "0")
	comment "Looks good: setup program gives exitcode zero"
else
	comment "Setup program gives a exitcode unequal zero: " + $ExitCode$
	if ($ExitCode$ = "1605")
		comment "ERROR_UNKNOWN_PRODUCT	1605	This action is only valid for products that are currently installed."
		comment "Uninstall of a not installed product failed - no problem"
	else
		if ($ExitCode$ = "1641")
			comment "looks good: setup program gives exitcode 1641"
			comment "ERROR_SUCCESS_REBOOT_INITIATED	1641	The installer has initiated a restart. This message is indicative of a success."
		else
			if ($ExitCode$ = "3010")
				comment "looks good: setup program gives exitcode 3010"
				comment "ERROR_SUCCESS_REBOOT_REQUIRED	3010	A restart is required to complete the install. This message is indicative of a success."
			else
				logError "Fatal: Setup program gives an unknown exitcode unequal zero: " + $ExitCode$
				isFatalError
			endif
		endif
	endif
endif

[Sub_searchApp32]
set $appKey$ = "[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + "$app$" + "] " + $appKeyString$
Set $testName$ = GetRegistryStringValue32($appKey$)
if contains($testName$,$appString$)
	set $appKey$ = "[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + "$app$" + "] Comments"
	Set $testName$ = GetRegistryStringValue32($appKey$)
	if not(contains(lower($testName$),lower("Installed with OPSI")))
		set $appKey$ = "[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + "$app$" + "] UninstallString"
		Set $testName$ = GetRegistryStringValue32($appKey$)
		if contains(lower($testName$),lower("MsiExec.exe"))
			set $UninstallCommandList$ = $UninstallCommandList$ + '"%SystemRoot%\system32\msiexec.exe" /x ' + '"$app$"' + ' /qb-! REBOOT=ReallySuppress::'
		endif
	endif		
endif
 
[Sub_searchApp64]
set $appKey$ = "[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + "$app$" + "] " + $appKeyString$
Set $testName$ = GetRegistryStringValue64($appKey$)
if contains($testName$,$appString$)
	set $appKey$ = "[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + "$app$" + "] Comments"
	Set $testName$ = GetRegistryStringValue64($appKey$)
	if not(contains(lower($testName$),lower("Installed with OPSI")))
		set $appKey$ = "[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + "$app$" + "] UninstallString"
		Set $testName$ = GetRegistryStringValue64($appKey$)
		if contains(lower($testName$),lower("MsiExec.exe"))
			set $UninstallCommandList$ = $UninstallCommandList$ + '"%SystemRoot%\system32\msiexec.exe" /x ' + '"$app$"' + ' /qb-! REBOOT=ReallySuppress::'
		endif
	endif
endif
Set $appString$ to the value you need. I'm not sure what it is in this case.

Re: Registry Schleife Uninstall Strings

Verfasst: 29 Apr 2019, 10:55
von thomas.besser
Schau dir vllt mal folgende lokale Funktion an: https://github.com/opsi4instituts/lib/b ... ys.opsiinc

Damit findest du mit dem richtigen Suchbegriff alle Keys und kannst dann ganz einfach alle "UninstallString" holen und ausführen.

Gruß
Thomas