Private Sub cmdPRC_ID_Click() ' Author: Jason Morris ' Date Created: 11/8/2007 ' Description: This will update the specified logon IDs with the new supplied logon script. ' It will output the original script file and pass/fail results if the change completed. ' If an error occurs, program continues processing On Error Resume Next ' Defines Variables Dim strScript As String ' Used to contain the desired logon script name from the spreadsheet Dim strDomain As String ' Used to obtain the Domain of the current user ID from the spreadsheet Dim strUserID As String ' Used to obtain the user ID of the current line being worked. Dim curCell As Integer ' Counted to determine what line is being processed. Dim objUser ' Used to pull the User Account to be read and modified. ' Set initial values curCell = 19 ' First row of data. strScript = Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Cells(curCell, 3) strUserID = Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Cells(curCell, 2) strDomain = Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Cells(curCell, 1) ' Processing loop to run until no value is provided for the UserID. ' Once an empty UserID cell is reached, end of file is assumed. Do Until strUserID = "" ' Sets objUser to the current user being processed by calling the ReturnDN function Set objUser = GetObject(ReturnDN(strDomain, strUserID, True)) ' Updates the Original Logon Script field for the current processed user ID Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Range("D" & curCell).Select ActiveCell.FormulaR1C1 = objUser.scriptPath Selection.Font.Bold = False ' Updates the current user ID's logon script with the one specified on the spreadsheet objUser.scriptPath = strScript ' Saves the changes objUser.SetInfo ' Determines if the update was successful and updates the Status field accordingly ' Refresh objUser Set objUser = GetObject(ReturnDN(strDomain, strUserID, True)) If Trim$(LCase$(objUser.sAMAccountName)) = Trim$(LCase$(strUserID)) Then Select Case Trim$(LCase$(objUser.scriptPath)) ' Checks if the current logon script assigned to the user id ' matches the changed that was attempted. Case Is = Trim$(LCase$(strScript)) ' If change was successful, mark the status as Complete Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Range("E" & curCell).Select ActiveCell.FormulaR1C1 = "Complete" Selection.Font.Bold = False Selection.Font.ColorIndex = 0 ' Checks if the current logon script assigned to the user id ' does not match the change that was attempted. Case Is <> Trim$(LCase$(strScript)) ' If change failed, mark status as *** INCOMPLETE *** with red text Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Range("E" & curCell).Select ActiveCell.FormulaR1C1 = "*** INCOMPLETE ***" Selection.Font.Bold = False Selection.Font.ColorIndex = 3 End Select Else ' If the ID does not exist, update status to *** ID not on Domain *** Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Range("E" & curCell).Select ActiveCell.FormulaR1C1 = "*** ID not on Domain ***" Selection.Font.Bold = False Selection.Font.ColorIndex = 0 End If ' Increments the current line being worked and updates all related variables curCell = curCell + 1 strScript = Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Cells(curCell, 3) strUserID = Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Cells(curCell, 2) strDomain = Workbooks("Update Logon Scripts.xls").Worksheets("Update Logon Script Console").Cells(curCell, 1) Loop ' Returns focus to the top of the spreadsheet ThisWorkbook.Worksheets(1).Range("A1").Select ' Indicates that this sub-routine has finished MsgBox "End of file reached at row " & curCell & "!" End Sub '=========================================================== ' Returns the distinguished name of the user in LDAP format. '=========================================================== Function ReturnDN(sDomain, sUser, bNetbios) On Error Resume Next Dim Trans Set Trans = CreateObject("NameTranslate") Trans.Init 1, sDomain If bNetbios Then Trans.Set 3, sDomain & "\" & sUser Else Trans.Set 9, sUser & "@" & sDomain End If ReturnDN = "LDAP://" & Trans.Get(1) Set Trans = Nothing End Function