From ZENWorks Wiki
Example Registry read and Write File. Includes a logger
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=G:\Software\Utilities\AutoIT\prep_lights_for_out.exe
#AutoIt3Wrapper_Res_Comment=This sets the autoadminlogin context to that of the last successful authenticated context. Also sets the autoadminlogin registry values by reading a reg file.
#AutoIt3Wrapper_Res_Fileversion=1.0.0.2
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;AUTHOR: Jared Jennings jjennings@datatechnique.com
;DATE: August 14, 2008
;PURPOSE: Read the default DNS context, which is the context of the last successfull login.
; Set this in Novell Location Profiles so that auto admin will login to the correct location.
#include <Date.au3>
;Default context of last successful login
$defaultContextPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Novell\NWGINA\Login Screen"
;Novell Login profile context so that we try this context first.
$profileContextPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Location Profiles\Services\{1E6CEEA1-FB73-11CF-BD76-00001B27DA23}\Default\Tab1"
;if Not FileExists("autoadminlogin-zenuser.reg") Then
; ConsoleWrite("A reg file autoadminlogin-zenuser.reg MUST exist in the same Directory as this exe, which contains the registry keys for autoadminlogin" & @CRLF)
; logErrors("A reg file autoadminlogin-zenuser.reg MUST exist in the same Directory as this exe, which contains the registry keys for autoadminlogin", @error)
;Else
;Run regedit and set the registry values for autoadmin login
; Run("regedit /s autoadminlogin-zenuser.reg", "", @SW_HIDE)
; if @error then logErrors("Failed to read registry file which contains autoadminlogin settings", @error)
;EndIf
;Read the default context and set to variable $defaultContext
$defaultContext = RegRead($defaultContextPath, "DefaultNDSContext")
if @error then logErrors("Failed to read Registry Key" & $defaultContextPath, @error) ;log the errors
;Echo the context to a message box for debug purposes
;MsgBox(4096, "Setting Auto Admin LOGIN context to:", $defaultContext)
logErrors("Setting Auto Admin LOGIN context to", $defaultContext)
;Set the context in the auto admin login field.
RegWrite($profileContextPath, "Context", "REG_SZ", $defaultContext)
if @error then logErrors("Failed to read Registry Key" & $profileContextPath, @error) ;log the errors
;Capture any errors
;$friendlyErrorMessage = display message to write
;$errorMessage = Error message to write
Func logErrors($friendlyErrorMessage, $errorMessage)
$file = FileOpen(@TempDir & "\" & "lightsOutErrors.log", 1)
; Check if file opened for writing OK
If $file = -1 Then
; MsgBox(0, "Error", "Unable to open file.")
Exit
Else
;Write error to log file
FileWrite($file, _DateTimeFormat( _NowCalc(),2) & "---" & $friendlyErrorMessage & " VALUE:" & $errorMessage & @CRLF)
EndIf
EndFunc