none
MDT ztigather not calling userexit function RRS feed

  • Question

  • Hello everyone,

    I followed some tips on use of userexit on Michel's answer http://social.technet.microsoft.com/Forums/en-US/f32c9757-d49c-4bd8-b496-8904ff04d12b/priority-properties-and-userexit-script?forum=mdt .

    I have this section on CS.ini:

    [Settings]
    Priority=Default, TaskSequenceID, MacAddress, NetworkConfig, LocaleConfig, BackupConfig, MigrationConfig, OrganizationalUnits, DeployConfig, Computername, AppConfig
    Properties=APPSHARE
    
    [...]
    
    [Computername]
    OSDComputerName=#GetOfflineComputerName()#
    UserExit=Custom\UserExitDynComputerName.vbs
    

    I tried on putting userexit script on %SCRIPTROOT% (not on Custom subfolder) with same result.

    APPSHARE is a property that I created not related to this script.

    Then, the script  UserExitDynComputerName.vbs:

    Option Explicit
    
    Function UserExit(sType, sWhen, sDetail, bSkip)
    	
    	oLogging.CreateEntry "Entered UserExit ", LogTypeInfo
    	oLogging.CreateEntry "Arguments to UserExit " & sType & ", " & sWhen & ", " & sDetail & ", " & bSkip , LogTypeInfo
    	
    	UserExit = Success
    End Function
    
    Public Function GetOfflineComputerName()
    	int intLastPCIRLastComputer
    	oLogging.CreateEntry "entered GetOfflineComputername.", LogTypeInfo
    	If UCase(oEnvironment.Item("OSVERSION")) = "WINPE" Then
    		If MountOfflineRegistry Then
    			GetOfflineComputerName = RegistryRead ("HKLM\offlineHKLM\ControlSet001\Services\Tcpip\Parameters\Hostname")
    			UnMountOfflineRegistry
    		Else
    			'GetOfflineComputerName = default
    			FQDomain = "ACME.COM"
    			strQueryComputers = "<LDAP://" & FQDomain & ">;(&(objectCategory=computer)(objectClass=computer));ADsPath,samAccountName;subtree"
    			ADComputers = QueryADO(FQDomain, strQueryComputers)
    			ComputerBase = "SOMETHING_BLAH"
    			While Not ADComputers.EOF
    				strReadComputer = ADComputers("samAccountName")
    				if Left(strReadComputer, 4) = ComputerBase then
    					LastPCIRComputer = strReadComputer
    				End if
    				ADComputers.MoveNext
    			Wend
    			intLastPCIRLastComputer = CInt(Rigth(PCIRComputer, 4))
    			Computername = ComputerBase & CStr(intLastPCIRLastComputer + 1)
    		End If
    	Else
    		GetOfflineComputerName = oShell.ExpandEnvironmentStrings("%Computername%")
    	End If
    
    End Function
    
    Public Function QueryADO(FQDomain, LDAPpath)
    	Const adUseClient = 3
    	
    	Set objRootDomain = GetObject("LDAP://" & FQDomain)
    	Set Conn = CreateObject("ADODB.Connection")
    	Set Comm = createobject("ADODB.Command")
    	Set rs = CreateObject("ADODB.Recordset")
    	
    	Conn.Provider = "ADsDSOObject"
    	Conn.Open "ADs Provider"
    	Conn.CursorLocation = adUseClient
    	
    	Comm.ActiveConnection = Conn
    	Comm.Properties("Page Size") = 1000
    	Comm.CommandText = LDAPpath
    	Comm.Properties("Sort on") = "name"
    	
    	Set rs = comm.Execute
    	
    	QueryADO = rs
    End Function
    
    Private Function MountOfflineRegistry()
    	oLogging.CreateEntry "Entered MountOfflineRegistry", LogTypeInfo
    	Dim iRet, drv, sOldSystem
    	sOldSystem = ""
    	For Each drv In Array("C", "D", "E", "F")
    		oLogging.CreateEntry "Checking drive " & drv & " for registry", LogTypeInfo
    		If ofso.FileExists(drv & ":\windows\system32\config\system") Then
    			sOldSystem = drv & ":\windows\system32\config\system"
    			Exit For
    		End If
    	Next
    	
    	If sOldSystem <> "" Then
    		oLogging.CreateEntry "Found offline registry at " & sOldSystem, LogTypeInfo
    	
    	Else
    		oLogging.CreateEntry "Could not find old system registry.", LogTypeInfo
    		MountOfflineRegistry = False
    		Exit Function
    	End If
    	
    	oLogging.CreateEntry "Mounting Offline registry " & sOldSystem, LogTypeInfo
    	On Error Resume Next
    	iret = oShell.Run ("reg load HKLM\offlineHKLM " & sOldSystem, 0, True)
    	On Error Goto 0
    	If iRet <> 0 Then
    		oLogging.CreateEntry "Could not mount offline registry. Code returned " & iRet, LogTypeInfo
    		MountOfflineRegistry = False
    		Exit Function
    	Else
    		oLogging.CreateEntry "Offline registry now mounted at HKLM\offlineHKLM", LogTypeInfo 
    		MountOfflineRegistry = True
    		Exit Function
    	End if
    End Function
    
    Private Function UnMountOfflineRegistry()
    	Dim iRet
    	oLogging.CreateEntry "Entered UnMountOfflineRegistry", LogTypeInfo
    	oLogging.CreateEntry "About to unmount offline registry", LogtypeInfo
    	On Error Resume Next
    	iRet = oShell.Run("REG UNLOAD HKLM\OFFLINEHKLM", 0, True)
    	On Error Goto 0
    	If iRet <> 0 Then
    		oLogging.CreateEntry "Could not unmount offline registry. Code returned " & iRet, LogTypeInfo
    		UnMountOfflineRegistry = False
    	Else
    		oLogging.CreateEntry "Offline registry now unmounted", LogTypeInfo
    		UnMountOfflineRegistry = True
    	End If
    End Function
    
    Private Function RegistryRead(sPath)
    	Dim sRet
    	oLogging.CreateEntry "Entered RegistryRead", LogTypeInfo
    	oLogging.CreateEntry "About to read registry value " & sPath, LogTypeInfo
    	On Error Resume Next
    	sRet = oShell.RegRead(sPath) & ""
    	On Error Goto 0
    	If sRet <> "" Then
    		oLogging.CreateEntry "Registry Value read " & sRet, LogTypeInfo
    		RegistryRead = sRet
    		Exit Function
    	Else
    		oLogging.CreateEntry "Registry Value is blank", LogTypeInfo
    		RegistryRead = ""
    		Exit Function
    	End If
    End Function

    And finally,

    ZTIGather.log (SMSTrace parsed):

    [...]

    ------ Processing the [COMPUTERNAME] section ------ ZTIGather Entered UserExit ZTIGather Arguments to UserExit SECTION, BEFORE, COMPUTERNAME, False ZTIGather User exit "\\SERVIR3\DEPLOYMENT$\Scripts\Custom\UserExitDynComputerName.vbs" called successfully, skip = False. ZTIGather Property OSDCOMPUTERNAME is now = #GetOfflineComputername()# ZTIGather Using from [COMPUTERNAME]: OSDCOMPUTERNAME = #GetOfflineComputername()# ZTIGather Entered UserExit ZTIGather Arguments to UserExit SECTION, AFTER, COMPUTERNAME, False ZTIGather User exit "\\SERVIR3\DEPLOYMENT$\Scripts\Custom\UserExitDynComputerName.vbs" called successfully, skip = False. ZTIGather Update progress [ 90 ] : Processing rule: APPCONFIG ZTIGather ------ Processing the [APPCONFIG] section ------ ZTIGather

    [...]

    Why is it setting Property OSDCOMPUTERNAME to #GetOfflineComputername()#

    and not calling userexit script function GetOfflineComputerName(), to get the ret value?

    Thanks to all,

    Joan.

    Thursday, October 31, 2013 4:27 PM

Answers

  • Your script has a bug in it:

    Public Function GetOfflineComputerName()
    	int intLastPCIRLastComputer
    

    Int IntLastPCIRLastComputer is *NOT* a valid VBScript statement. This causes the *entire* function to fail. Failed functions do not get evaluated which is why you get the # GetOfflineComputerName() # value.


    Keith Garner - keithga.wordpress.com

    Monday, November 4, 2013 4:03 AM
    Moderator

All replies

  • Your script has a bug in it:

    Public Function GetOfflineComputerName()
    	int intLastPCIRLastComputer
    

    Int IntLastPCIRLastComputer is *NOT* a valid VBScript statement. This causes the *entire* function to fail. Failed functions do not get evaluated which is why you get the # GetOfflineComputerName() # value.


    Keith Garner - keithga.wordpress.com

    Monday, November 4, 2013 4:03 AM
    Moderator
  • OK. Now is working like a charm.

    Not so familiar with VB ain't VBScript. I didn't got any error on logs so I didn't realize it. Should get a good IDE :)

    Could I get more output from userexit (i.e. traceback line error)? Maybe setting DEBUG:TRUE?

    Thanks for all!

    Tuesday, November 5, 2013 6:36 PM