0

我正在尝试更改我域中的所有内置 Windows 本地管理员名称。新名称将是“管理员”,但似乎我的脚本无法读取 excel 数据(服务器|旧帐户名称)。

DIM strPassword, strAdminUserName, strNewAdminUserName

Dim strExcelPath, objExcel, objSheet, intRow


'''''
'Spreadsheet file.
strExcelPath = "c:\List.xls"

' Bind to Excel object.
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Excel application not found."
    Wscript.Quit
End If
On Error GoTo 0

' Open spreadsheet.
On Error Resume Next
objExcel.Workbooks.Open strExcelPath
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Spreadsheet cannot be opened: " & strExcelPath
    Wscript.Quit
End If
On Error GoTo 0

' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)



intRow = 2
Do While objSheet.Cells(intRow, 1).Value <> ""
    comp = objSheet.Cells(intRow, 1).Value
    strAdminUserName = objSheet.Cells(intRow, 2).Value
    strNewAdminUserName = "Administrator"   
On Error Resume Next



' Rename a local user account on a given computer

    SET objComputer = GetObject("WinNT://" & Comp)
    SET objUser = GetObject("WinNT://" & Comp & "/" & strAdminUserName & ",user")
    IF err.number = 0 THEN
        objComputer.MoveHere objUser.ADsPath,strNewAdminUserName
    END IF
    ON ERROR GOTO 0
loop

' Close the workbook.
objExcel.ActiveWorkbook.Close

' Quit Excel.
objExcel.Application.Quit

Wscript.Echo "Done"

任何意见/评论将不胜感激。

4

0 回答 0