Table of Contents

Microsoft Office 2010, 2013, 2016 Activation

Author Dominik Daehn, based on Activate-Win Code by uib Gmbh

Microsoft Office 2010, 2013, 2016 Activation.

Tested with:

Tree:

CLIENT_DATA
  ├ activate-office.png
  └ setup.opsiscript

setup.opsiscript

; Author Dominik Daehn, based on Activate-Win Code by uib Gmbh
 
[Actions]
requiredWinstVersion >= "4.11.3.1"
 
DefVar $ProductId$
DefVar $ProductName$
DefVar $InstallDir$
DefVar $Office2010$
DefVar $Office2013$
DefVar $Office2016$
DefVar $ActivationFile$
DefVar $ActivationPfad$
DefVar $OfficeVersion$
DefVar $LogDir$
DefVar $LicenseRequired$
DefVar $LicenseKey$
DefVar $LicensePool$
DefVar $poolOrKey$
DefVar $source$
DefVar $httpproxy$
DefVar $exitcodeState$
DefVar $exitcodeActivation$
DefVar $SystemType$
 
; ----------------------------------------------------------------
 
Set $ProductId$     	= "activate-office"
Set $ProductName$	= "Microsoft Office Produktaktivierung"
Set $InstallDir$ 	= "Microsoft Office"
Set $Office2010$	= "Office14"
Set $Office2013$	= "Office15"
Set $Office2016$	= "Office16"
Set $ActivationFile$ 	= "ospp.vbs"
Set $SystemType$ 	= GetSystemType
Set $LogDir$ 		= "%SystemDrive%\tmp"
 
; ----------------------------------------------------------------
 
if GetMsVersionInfo > "6" 
;operater was wrong way. 
	LogError "This is for NT 6 (Vista) and above"
	isFatalError
else
 
	if FileExists("%ProgramFiles64Dir%\" + $InstallDir$ + "\" + $Office2010$ + "\" + $ActivationFile$)
		set $ActivationPfad$ = "%ProgramFiles64Dir%"
		set $OfficeVersion$ = $Office2010$
	endif
 
	if FileExists("%ProgramFiles64Dir%\" + $InstallDir$ + "\" + $Office2013$ + "\" + $ActivationFile$)
		set $ActivationPfad$ = "%ProgramFiles64Dir%"
		set $OfficeVersion$ = $Office2013$
	endif
 
	if FileExists("%ProgramFiles64Dir%\" + $InstallDir$ + "\" + $Office2016$ + "\" + $ActivationFile$)
		set $ActivationPfad$ = "%ProgramFiles64Dir%"
		set $OfficeVersion$ = $Office2016$
	endif
 
	if $SystemType$ = "64 Bit System"
		if FileExists("%ProgramFiles32Dir%\" + $InstallDir$ + "\" + $Office2010$ + "\" + $ActivationFile$)
			set $ActivationPfad$ = "%ProgramFiles32Dir%"
			set $OfficeVersion$ = $Office2010$
		endif
 
		if FileExists("%ProgramFiles32Dir%\" + $InstallDir$ + "\" + $Office2013$ + "\" + $ActivationFile$)
			set $ActivationPfad$ = "%ProgramFiles32Dir%"
			set $OfficeVersion$ = $Office2013$
		endif
 
		if FileExists("%ProgramFiles32Dir%\" + $InstallDir$ + "\" + $Office2016$ + "\" + $ActivationFile$)
			set $ActivationPfad$ = "%ProgramFiles32Dir%"
			set $OfficeVersion$ = $Office2016$
		endif
    endif
 
	comment "Show product picture"
	ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductName$
 
	Message "Installing " + $ProductId$ + " ..."
 
	set $poolOrKey$ = GetProductProperty("Poolid-or-Licensekey","")
	set $source$ = GetProductProperty("method","only-activate")
	set $httpproxy$ = GetProductProperty("httpproxy","")
 
	comment "Check Status"
	DosInAnIcon_status_office 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
			Set $LicenseRequired$ = "false"
			Set $LicensePool$     = ""
			set $LicenseKey$ = $poolOrKey$
			comment " use key "+$LicenseKey$
		endif
 
		comment "Set the Key"
		DosInAnIcon_set_key winst /sysnative
 
		comment "Check Status"
		DosInAnIcon_status_office winst /sysnative
		set $exitcodeState$ = getLastExitCode
	endif
 
	comment "Start Activation"
	DosInAnIcon_activate  winst /sysnative
	set $exitcodeActivation$ = getLastExitCode
 
	comment "Check Status"
	DosInAnIcon_status_office 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
 
	DosInAnIcon_resetproxy_win7 winst /sysnative
 
endif
 
[DosInAnIcon_set_key]	
cscript //b "$ActivationPfad$\$InstallDir$\$OfficeVersion$\$ActivationFile$" /inpkey:$LicenseKey$
exit %ERRORLEVEL%
 
[DosInAnIcon_activate]	
cscript //b "$ActivationPfad$\$InstallDir$\$OfficeVersion$\$ActivationFile$" /act
exit %ERRORLEVEL%
 
[DosInAnIcon_status_office]
cscript "$ActivationPfad$\$InstallDir$\$OfficeVersion$\$ActivationFile$" /dstatus
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 $httpproxy$
 
[DosInAnIcon_resetproxy_win7]
netsh.exe winhttp reset proxy

control

[Package]
version: 1
depends: 
incremental: False

[Product]
type: localboot
id: activate-office
name: Microsoft Office Activation
description: Microsoft Office 2010, 2013, 2016 Activation
advice: 
version: 1.0
priority: 0
licenseRequired: True
productClasses: 
setupScript: setup.opsiscript
uninstallScript: uninstall.opsiscript
updateScript: 
alwaysScript: 
onceScript: 
customScript: 
userLoginScript: 

[ProductProperty]
type: unicode
name: poolid-or-licensekey
multivalue: False
editable: True
description: id from opsi-license-management-pool or license key

[ProductProperty]
type: unicode
name: method
multivalue: False
editable: False
description: What should we do:
 "only-activate" : activate with the installed key
 "opsi License management": get key from opsi (need the poolid in other property) and activate
 "licensekey from property": get licensekey from property 'poolid-or-licensekey' and activate
values: ["licensekey from property", "only-activate", "opsi License management"]
default: ["only-activate"]

[ProductProperty]
type: unicode
name: httpproxy
multivalue: False
editable: True
description: httpproxy needed for activation proxy.mycompany.com:3218
values: [""]
default: [""]

[Changelog]
activate-office (1.0-1) stable; urgency=low

  * Initial package

 -- Dominik Daehn <...>  Tue, 5 Jan 2016