User Tools

Site Tools


userspace:reboot-control

This Function helps to store, read and update a reboot flag in your registry.

Modes:

  write => Write a new rebootflag to registry or update to a new value
  read => Read actual value from registry
  delete => Remove reboot flag from registry
  

Syntax:
rebootcontrol(“<Counter> | <auto>”,“<mode>”)

Examples:
set $rebooted$ = rebootcontrol(“auto”,“read”)
Read the actual value from the Registry, you will get a string value from this function.

set $DummyVar$ = rebootcontrol(“auto”,“write”)
Write a new flag to the registry. If no flag is stored in the registry, the script creates a new one.
If a flag is found, the value is increased.

set $DummyVar$ = rebootcontrol(“2”,“write”)
Write the value “2” to the reboot flag

set $DummyVar$ = rebootcontrol(“auto”,“delete”)
Deletes the flag from the registry, the first option (auto) must be present but is ignored.

DefFunc rebootcontrol($counter$ : string, $mode$ : string) : string
	DefVar $debug$
	DefVar $productname$
	set $debug$ = "false"
	
	if $debug$ = "True"
		DefVar $counter$
		DefVar $mode$

		set $counter$ = "1"
		set $mode$ = "write"
		set $ProductName$ = "TEST"
	else
		message "debug off"
		message "detecting product-ID"
		message "%installingProdName%"
		set $ProductName$ = "%installingProdName%"
	endif
	
	DefVar $WinstRegKey$
	DefVar $Flag$
	
	
	Set $WinstRegKey$ = "HKLM\SOFTWARE\opsi.org\winst\"+$ProductName$+""
	
	
	switch $mode$	
		case "write"
			message "Writing Reboot Counter"
			if $counter$ = "auto"
				Set $counter$ = getregistrystringvalueSysNative("["+$WinstRegKey$+"]RebootFlag")
				set $counter$ = calculate($counter$+"+"+"1")
				message = $counter$
				Registry_SaveRebootFlag /sysnative
			else
				Registry_SaveRebootFlag /sysnative
			endif
			set $result$ = $counter$ 

		endCase
		
		case "read"
			message "Reading Reboot Counter"
			Set $counter$ = getregistrystringvalueSysNative("["+$WinstRegKey$+"]RebootFlag")
			set $result$ = $counter$ 
		endCase
		
		case "delete"
			message "Delete Reboot Counter"
			Registry_delete_RebootCounter /sysnative
			set $result$ = "deleted"
		endCase
		
		DefaultCase
			message "no mode definiert ERROR"
			set $result$ = "ERROR$
			isFatalError
		endCase
	EndSwitch
			
			

[Registry_SaveRebootFlag]
openKey [$WinstRegKey$]
set "RebootFlag" = "$counter$"

[Registry_delete_RebootCounter]
deletekey [$WinstRegKey$]

endfunc
userspace/reboot-control.txt · Last modified: 2021/08/23 08:37 (external edit)