====== removeMSI ======
**CALL:**
set $result$ = removeMSI("dummy")
**NOTE:** \\
$result$ must be from Type "StringList"\\
====== Usage ======
Check WINST Manual: \\
[[https://download.uib.de/opsi_stable/doc/html/en/opsi-winst-manual/opsi-winst-manual.html#opsi-winst-commands-localfunctions |9.22. Local functions]] \\
[[https://download.uib.de/opsi_stable/doc/html/en/opsi-winst-manual/opsi-winst-manual.html#opsi-winst-commands-localfunctions|9.23. Import von Library Funktionen]]
===== config =====
Create a file named msi.conf in your %ScriptDir% \\
In this file, you have to include all MSIIDs you want to remove in the following format: \\
Desciption of your Software:{your-msi-id}\\
For example:
vcredist_x64_2010:{1D8E6291-B0D5-35EC-8441-6616F567A0F7}
===== Retrurn StringList =====
You will get the following information back (in case of an error):
[0] = Description\\
[1] = ExitCode\\
[2] = Error Desciption (If known, otherwise UNKNOWN)\\
In case of ExitCode 0, 1605, 1641 or 3010 you will only get the following Information back:
[0] = All Products uninstalled\\
[1] = 0\\
[2] = All Products uninstalled
===== CODE =====
DefFunc RemoveMSI(val $remove$ : string) : stringlist
	DefStringList $msiidsAndDescription$
	DefStringList $transformList$
	DefVar $ID$
	DefVar $description$
	DefVar $ExitCode$
	
	set $msiidsAndDescription$ =	loadTextFile ("%scriptpath%\msi.conf")
	
	for %i% in $msiidsAndDescription$ do sub_extract_id_and_description
	
	[sub_extract_id_and_description]	
	set $transformList$ = splitstring("%i%",":")
	
	set $Description$ = takestring(0,$transformList$)
	set $ID$ = takestring(1,$transformList$)
	set $transformList$ = emptylist($transformList$)
	Message "remove "+$Description$
	
	
	if not (GetRegistryStringValue32("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $ID$ + "] DisplayName") = "")
		comment "MSI id " + $ID$ + " found in registry, starting msiexec to uninstall"
		Winbatch_uninstall_msi
		sub_check_exitcode
	endif
	
	if not (GetRegistryStringValue64("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $ID$ + "] DisplayName") = "")
		comment "MSI id " + $ID + " found in registry, starting msiexec to uninstall"
		Winbatch_uninstall_msi
		sub_check_exitcode
	endif
	
	
	[Winbatch_uninstall_msi]
	msiexec /x $ID$ /qb-! REBOOT=ReallySuppress
	
	[sub_check_exitcode]
	set $ExitCode$ = getLastExitCode
	Switch $ExitCode$
        Case "0"
               comment "Looks good: setup program gives exitcode zero"
               set $result$ = emptylist($result$)
               set $result$ = addToList($result$,"All Products uninstalled")
               set $result$ = addToList($result$,"0")
               set $result$ = addToList($result$,"All Products uninstalled")
        EndCase
        case "1605"
          		set $result$ = addToList($result$,$Description$)
                set $result$ = addToList($result$,$ExitCode$)
                set $result$ = addToList($result$,"ERROR_UNKNOWN_PRODUCT	1605	This action is only valid for products that are currently installed")
		EndCase
		case "1641"
          		set $result$ = addToList($result$,$Description$)
                set $result$ = addToList($result$,$ExitCode$)
                set $result$ = addToList($result$,"ERROR_SUCCESS_REBOOT_INITIATED	1641	The installer has initiated a restart. This message is indicative of a success.")
		EndCase
		case "3010"
          		set $result$ = addToList($result$,$Description$)
                set $result$ = addToList($result$,$ExitCode$)
                set $result$ = addToList($result$,"ERROR_SUCCESS_REBOOT_REQUIRED	3010	A restart is required to complete the install. This message is indicative of a success.")
		EndCase
        DefaultCase
        		Message $exitcode$
                set $result$ = addToList($result$,$Description$)
                set $result$ = addToList($result$,$ExitCode$)
                set $result$ = addToList($result$,"UNKNOWN")
                isFatalError
        EndCase
     EndSwitch
EndFunc
	
===== Sample usage in delsub.opsiscript =====
All MSI Software Packages defined in the msi.conf file will be removed.
importLib "removeMSI.opsiinc"
DefStringList $result$
set $result$ = removeMSI("dummy")
===== Questions, bug reports, feature request, or just an idea for new crazy functions ??? =====
This Function is Part of my OPSI-WINST-LIBRARY Bundle, which home is on GitHUB.\\
Feel free to share your Ideas for new functions or contact me there for bug reports. \\
[[https://github.com/Venice-89/OPSI-WINST-Library|OPSI-WINST-Library on GitHUB]]