Seite 1 von 1

Scripte REG werte setzten nach Installation

Verfasst: 23 Jul 2015, 18:49
von RITsol
Einen schönen guten Abend @all,

da ich mich in den letzten zwei Monaten ausschließlich mit OPSI beschäftigt, hauptsächlich Installation und Konfiguration.

Nun bin ich dabei Software zu paketieren und ggf. anzupassen für die Verteilung.

Da ich viel mit Deployment Systeme arbeite und auch einen Standard (ISO/IEC 25051) habe würde ich dieses auch mit der OPSI umsetzten wollen.

z.B. nach einer erfolgreichen Installation sollte eine Stemple in der Registry gesetzt werden

HKLM\Software\{Fa. Name}\Signature\ProductID
Creator=Admin
Customer={Fa. Name}
SoftwareCode=00001
Vendor=Igor-Pavlov
ProgramName=7Zip
ProgramVersion=9.20
DateOfCreation=10.03.2014
PackageVersion=1.0
ProductCode={23170F69-40C1-2702-0920-000001000000}
Language=DE
PackageType=C
Type=x64

Nun habe ich schon versucht dies umzusetzen, aber ich bekomm das einfach nicht hin (der Wald und die Bäume :| ) :oops:

Noch schöner wäre, dass geprüft wird ob die Installation erfolgreich durchgelaufen ist und das ich alles über Variablen lösen könnte.

If ($ExitCode$ = "0" OR $ExitCode$ ="1641" OR $ExitCode$ ="3010")

openkey [HKLM\FaName\$ProductId$]
set "Software" = "$ProductId$"
set "Version" = "9.22"
endif


Installation erfolgreich setzten der Reg werte


Code: Alles auswählen

; Copyright (c) uib gmbh (http://www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/en/credits/

[Actions]
requiredWinstVersion >= "4.11.3.3"

DefVar $MsiId$
DefVar $LogDir$
DefVar $ProductId$  
DefVar $MinimumSpace$
DefVar $ExitCode$
DefVar $ErrorMsg$
DefVar $LicenseRequired$
DefVar $LicenseKey$
DefVar $LicensePool$

Set $LogDir$ = "%SystemDrive%\tmp"

include_append "%ScriptPath%\check_msi_exitcode.opsiscript"
; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
;$ProductId$ should be the name of the product in opsi
; therefore please: only lower letters, no umlauts, 
; no white space use '-' as a seperator
Set $ProductId$       = "7-Zip"
Set $MinimumSpace$    = "8 MB"
; the path were we find the product after the installation
Set $LicenseRequired$ = "false"
Set $LicensePool$     = "p_" + $ProductId$
; ----------------------------------------------------------------

if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$))
	LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$
	isFatalError "No Space"
	; Stop process and set installation status to failed
else
	comment "Show product picture"
	ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$
	
	if FileExists("%ScriptPath%\delsub64.opsiscript")
		comment "Start uninstall sub section"
		Sub "%ScriptPath%\delsub64.opsiscript"
	endif
	
	Message "Installing " + $ProductId$ + " ..."
	
	if $LicenseRequired$ = "true"
		comment "Licensing required, reserve license and get license key"
		Sub_get_licensekey
	endif
	
	comment "Start setup program"
	ChangeDirectory "%SCRIPTPATH%"
	Winbatch_install
	Sub_check_exitcode
	Registry_TestPatch
endif

[Winbatch_install]
msiexec /i "%ScriptPath%\7z922-x64.msi"  /l* "$LogDir$\$ProductId$.install_log.txt" /qb! ALLUSERS=1 REBOOT=ReallySuppress

[Registry_TestPatch]

		openkey [HKLM\FaName\$ProductId$]
		set "Software"  = "$ProductId$"
		set "Version" =  "9.22"


[Sub_get_licensekey]
if opsiLicenseManagementEnabled
	comment "License management is enabled and will be used"

	comment "Trying to get a license key"
	Set $LicenseKey$ = demandLicenseKey ($LicensePool$)
	; If there is an assignment of exactly one licensepool to the product the following call is possible:
	; Set $LicenseKey$ = demandLicenseKey ("", $ProductId$)
	;
	; If there is an assignment of a license pool to a windows software id, it is possible to use:
	; DefVar $WindowsSoftwareId$
	; $WindowsSoftwareId$ = "..."
	; Set $LicenseKey$ = demandLicenseKey ("", "", $WindowsSoftwareId$)
	
	DefVar $ServiceErrorClass$
	set $ServiceErrorClass$ = getLastServiceErrorClass
	comment "Error class: " + $ServiceErrorClass$
	
	if $ServiceErrorClass$ = "None"
		comment "Everything fine, we got the license key '" + $LicenseKey$ + "'"
	else
		if $ServiceErrorClass$ = "LicenseConfigurationError"
			LogError "Fatal: license configuration must be corrected"
			LogError getLastServiceErrorMessage
			isFatalError
		else 
			if $ServiceErrorClass$ = "LicenseMissingError"
				LogError "Fatal: required license is not supplied"
				isFatalError
			endif
		endif
	endif
else
	LogError "Fatal: license required, but license management not enabled"
	isFatalError
endif

; Copyright (c) uib gmbh (http://www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/en/credits/

[Actions]
requiredWinstVersion >= "4.11.3.3"

DefVar $MsiId$
DefVar $LogDir$
DefVar $ProductId$  
DefVar $MinimumSpace$
DefVar $ExitCode$
DefVar $ErrorMsg$
DefVar $LicenseRequired$
DefVar $LicenseKey$
DefVar $LicensePool$

Set $LogDir$ = "%SystemDrive%\tmp"

include_append "%ScriptPath%\check_msi_exitcode.opsiscript"
; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
;$ProductId$ should be the name of the product in opsi
; therefore please: only lower letters, no umlauts, 
; no white space use '-' as a seperator
Set $ProductId$       = "7-Zip"
Set $MinimumSpace$    = "8 MB"
; the path were we find the product after the installation
Set $LicenseRequired$ = "false"
Set $LicensePool$     = "p_" + $ProductId$
; ----------------------------------------------------------------

if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$))
	LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$
	isFatalError "No Space"
	; Stop process and set installation status to failed
else
	comment "Show product picture"
	ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$
	
	if FileExists("%ScriptPath%\delsub64.opsiscript")
		comment "Start uninstall sub section"
		Sub "%ScriptPath%\delsub64.opsiscript"
	endif
	
	Message "Installing " + $ProductId$ + " ..."
	
	if $LicenseRequired$ = "true"
		comment "Licensing required, reserve license and get license key"
		Sub_get_licensekey
	endif
	
	comment "Start setup program"
	ChangeDirectory "%SCRIPTPATH%"
	Winbatch_install
	Sub_check_exitcode
	Registry_TestPatch
endif

[Winbatch_install]
msiexec /i "%ScriptPath%\7z922-x64.msi"  /l* "$LogDir$\$ProductId$.install_log.txt" /qb! ALLUSERS=1 REBOOT=ReallySuppress

[Registry_TestPatch]

		openkey [HKLM\FaName\$ProductId$]
		set "Software"  = "$ProductId$"
		set "Version" =  "9.22"


[Sub_get_licensekey]
if opsiLicenseManagementEnabled
	comment "License management is enabled and will be used"

	comment "Trying to get a license key"
	Set $LicenseKey$ = demandLicenseKey ($LicensePool$)
	; If there is an assignment of exactly one licensepool to the product the following call is possible:
	; Set $LicenseKey$ = demandLicenseKey ("", $ProductId$)
	;
	; If there is an assignment of a license pool to a windows software id, it is possible to use:
	; DefVar $WindowsSoftwareId$
	; $WindowsSoftwareId$ = "..."
	; Set $LicenseKey$ = demandLicenseKey ("", "", $WindowsSoftwareId$)
	
	DefVar $ServiceErrorClass$
	set $ServiceErrorClass$ = getLastServiceErrorClass
	comment "Error class: " + $ServiceErrorClass$
	
	if $ServiceErrorClass$ = "None"
		comment "Everything fine, we got the license key '" + $LicenseKey$ + "'"
	else
		if $ServiceErrorClass$ = "LicenseConfigurationError"
			LogError "Fatal: license configuration must be corrected"
			LogError getLastServiceErrorMessage
			isFatalError
		else 
			if $ServiceErrorClass$ = "LicenseMissingError"
				LogError "Fatal: required license is not supplied"
				isFatalError
			endif
		endif
	endif
else
	LogError "Fatal: license required, but license management not enabled"
	isFatalError
endif


ich bedanke mich schon mal im vor raus, für die Mühe.

Gruss
Markus

Re: Scripte REG werte setzten nach Installation

Verfasst: 27 Jul 2015, 14:26
von SisterOfMercy
RITsol hat geschrieben: If ($ExitCode$ = "0" OR $ExitCode$ ="1641" OR $ExitCode$ ="3010")

openkey [HKLM\FaName\$ProductId$]
set "Software" = "$ProductId$"
set "Version" = "9.22"
endif
This will not work. You need to call a secondary section (registry), and there set your registry settings.

Code: Alles auswählen

if ($INST_SystemType$ = "64 Bit System") and ($INST_MsVersion$ >= "6") 
	Registry_install /64Bit
endif

[Registry_install]
; set OpenVPN Service to automatic 
openkey [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\OpenVPNService]
set "Start" = REG_DWORD:00000002
However, you might not even need the if-statement for your example. In the template the winbatch part is followed by a Sub_check_exitcode which already checks for these exitcodes.

Re: Scripte REG werte setzten nach Installation

Verfasst: 27 Jul 2015, 17:43
von RITsol
Vielen danke für die Antwort, habe es gestern dann noch hinbekommen, etwas erweitert.

Da es ja ein setup64.opsiscript ist, reicht ja dieser Aufruf Registry_Branding /64Bit

Das habe ich dann auch mitbekommen mit den ExitCodes.

Was mir sehr gut gefällt, wenn man das über GetProductProperty löst.

Code: Alles auswählen

	       Registry_Branding /64Bit

		openkey [HKEY_LOCAL_MACHINE\Software\RITSOL\Signature\$Softwarecode$]
		Set "creator" = REG_SZ:"$creator$"
		Set "customer" = REG_SZ:"$customer$"
		Set "manufacturer" = REG_SZ:"$manufacturer$"
		Set "productcode" = REG_SZ:"$productcode$"
		Set "Language" = REG_SZ:"$Language$"
		Set "DateOfCreation" = REG_SZ:"$DateOfCreation$"
		Set "Platform" = REG_SZ:"$Platform$"
		Set "Installationtype" = REG_SZ:"$Installationtype$"
		Set "applicationname" = REG_SZ:"$applicationname$"
		Set "SoftwareVersion" = REG_SZ:"$SoftwareVersion$"
		Set "Softwarecode" = REG_SZ:"$Softwarecode$"
		set "packageversion" = REG_SZ:"$packageversion$"
		Set "PackageName" = REG_SZ:"$customer$_$manufacturer$_$applicationname$_$SoftwareVersion$_$Language$_$Platform$_$Installationtype$_$packageversion$_$Softwarecode$"
Jetzt hätte ich noch eine einzige Frage.

Würde gern noch ein Timstamp setzten in die Registry
DefVar $INSTALLTIME$
SET "TIMESTAMP" = REG_SZ:"$INSTALLTIME$"

Natürlich findet er die Variable nicht und ich hab irgendwie keine Idee wie ich diesen setzten kann, der Eintrag müsste das aktuelle Datum und die Zeit setzten. Hab auch schon so einiges versucht wie %DATE%_%TIME%, $TIMESTAMP$, _NowDate, _NowTime oder Now
hat da jemand eine Idee, wie ich das am besten umsetzte?

Gruß
Markus

Re: Scripte REG werte setzten nach Installation

Verfasst: 30 Jul 2015, 19:24
von RITsol
Hallo,


Bei diesem aufruf wird ne Windows variable genutzt.
Set $LogDir$ = "%SystemDrive%\tmp"
%date% %time% geht leider nicht, also hab ich es nun erst einmal so gelöst, vielleicht gibt es ja noch eine besser aber diese Lösung geht natürlich auch.

Code: Alles auswählen

DosInAnIcon_Reg winst /64bit

[DosInAnIcon_Reg]
@echo off
reg ADD "HKLM\Software\RITSOL\Signature\$Softwarecode$" /v "InstallDate_Time" /t REG_SZ /d "%DATE% %time:~0,8%" /f >NUL
Gruss

Markus