OEM Lizenzen zum Paket activate_win hinzufügen
Verfasst: 09 Aug 2017, 16:35
				
				Hallo, mir ist eben aufgefallen, dass OEM Lizenzen durch activate_win nicht installiert/aktiviert werden.
(OEM-Lizenzen lassen sich, meines Wissensstands nach, leider nicht per unattend.xml während der Betriebssysteminstallation auslesen)
Mein Vorschlag:
Hinzufügen des Werts "OEM licensekey" in die Propertylist "source"
Änderung an der setup.ins:
Erklärung:
Der hinzugefügte Code ist mit
------------------------------------<neu>------------------------------------
------------------------------------<\neu>------------------------------------
umklammert.
Es wird eine neue String-Liste $oemkey$ definiert, in der der Output der Sektion
gespeichert wird.
Dann wird der darin gespeicherte Lizenzschlüssel an $LicenseKey$ übergeben.
			(OEM-Lizenzen lassen sich, meines Wissensstands nach, leider nicht per unattend.xml während der Betriebssysteminstallation auslesen)
Mein Vorschlag:
Hinzufügen des Werts "OEM licensekey" in die Propertylist "source"
Änderung an der setup.ins:
Code: Alles auswählen
; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/credits/
[Actions]
requiredWinstVersion >= "4.11.5.14"
DefVar $LogDir$
DefVar $ProductId$  
DefVar $LicenseRequired$
DefVar $LicenseKey$
DefVar $LicensePool$
DefVar $poolOrKey$
DefVar $source$
DefVar $httpproxy$
DefVar $exitcodeState$
DefVar $exitcodeActivation$
;----------------------------------<neu>------------------------------------------
DefStringList $oemkey$
;----------------------------------<\neu>------------------------------------------
Set $LogDir$ = "%SystemDrive%\tmp"
Set $ProductId$       = "activate-win"
; ----------------------------------------------------------------
; see:
; http://technet.microsoft.com/en-us/library/ff793433.aspx
if CompareDotSeparatedNumbers(getMsVersionInfo, "<", "6.0")
	LogError "This is for NT 6 (Vista) and above"
	isFatalError
else
	
	comment "Show product picture"
	ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$
	
	
	Message "Installing " + $ProductId$ + " ..."
	
	set $poolOrKey$ = GetProductProperty("Poolid-or-Licensekey","")
	set $source$ = GetProductProperty("method","only-activate")
	set $httpproxy$ = GetProductProperty("httpproxy","")
	
	comment "Check Status"
	DosInAnIcon_status_win7 winst /sysnative
	set $exitcodeState$ = getLastExitCode
	
	if not ( $httpproxy$ = "" )
			comment "enable HTTP proxy, required for auto-activating"
			DosInAnIcon_setproxy_win7 winst /sysnative
	endif
	if not ($source$ = "only-activate")
		comment " we need a key..."
		if $source$ = "opsi License management"
			Set $LicenseRequired$ = "true"
			Set $LicensePool$     = $poolOrKey$
			comment " get key from license management with poolid "+$LicensePool$
			comment "Licensing required, reserve license and get license key"
			Sub_get_licensekey
		else
		
;----------------------------------------------------------------<neu>-------------------------------------
			if $source$ = "OEM licensekey"
				Set $LicenseRequired$ = "true"
				Set $LicensePool$     = ""
				comment "get key from BIOS"
				Set $oemkey$ = GetOutStreamFromSection ('DosInAnIcon_oem_key winst /sysnative')
				Set $LicenseKey$ = takeString(2,$oemkey$)
			else
				Set $LicenseRequired$ = "false"
				Set $LicensePool$     = ""
				set $LicenseKey$ = $poolOrKey$
				comment " use key "+$LicenseKey$
			endif
		endif
;----------------------------------------------------------------<\neu>-----------------------------------------
		comment "Set the Key"
		DosInAnIcon_set_key winst /sysnative
		
		comment "Check Status"
		DosInAnIcon_status_win7 winst /sysnative
		set $exitcodeState$ = getLastExitCode
	endif
	
	comment "Start Activation"
	DosInAnIcon_activate  winst /sysnative
	set $exitcodeActivation$ = getLastExitCode
	
	comment "Check Status"
	DosInAnIcon_status_win7 winst /sysnative
	set $exitcodeState$ = getLastExitCode
	
	comment "check the exit code of the activation..."
	if not ($exitcodeActivation$ = "0")
		LogError "Exitcode unequal zero: "+$exitcodeActivation$+" Activation seems to be failed !"
		isFatalError "activation failed"
	else
		comment "Activation seems to be successful: exit code = 0"
	endif
endif
;------------------------------------------------<neu>-------------------------------------------
[DosInAnIcon_oem_key]
wmic path softwarelicensingservice get OA3xOriginalProductkey | findstr \-
;------------------------------------------------<\neu>-------------------------------------------
[DosInAnIcon_set_key]	
cscript //b c:\windows\system32\slmgr.vbs /ipk $LicenseKey$
exit %ERRORLEVEL%
[DosInAnIcon_activate]	
cscript //b c:\windows\system32\slmgr.vbs /ato
exit %ERRORLEVEL%
[DosInAnIcon_status_win7]
cscript c:\windows\system32\slmgr.vbs /dli
exit %ERRORLEVEL%
[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
[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
[DosInAnIcon_setproxy_win7]
;netsh.exe winhttp set proxy proxy:3128 "<local>;*.mynet.local"
netsh.exe winhttp set proxy $httpproxy$
Der hinzugefügte Code ist mit
------------------------------------<neu>------------------------------------
------------------------------------<\neu>------------------------------------
umklammert.
Es wird eine neue String-Liste $oemkey$ definiert, in der der Output der Sektion
Code: Alles auswählen
[DosInAnIcon_oem_key]
wmic path softwarelicensingservice get OA3xOriginalProductkey | findstr \-
Dann wird der darin gespeicherte Lizenzschlüssel an $LicenseKey$ übergeben.