30岁,我在做什么?

.NET SQL数据库 Office开发 办公自动化

导航

使用脚本批量创建NT域帐户

Posted on 2007-01-31 23:00  .net 世界  阅读(401)  评论(0)    收藏  举报

使用脚本批量创建NT域帐户
yeyarong | 08/11 2006, 21:04
     今天接到任务要创建100个Windows NT 4.0域用户帐户的任务,虽然数量不多,但一个一个的去建也挺累的。于是自己编了个脚本自动创建帐号。
     这个脚本从C:盘下的Excel文件中读取用户名、全名、描述,然后创建帐号。再将密码进行修改,最后将用户加入到相应的组当中。
      脚本没有进行检测和校验功能,需要的朋友自己完善吧。另外,Excel格式第一行是表头。第一列是用户名,第二列是全名,第三列是描述。

On Error Resume Next

Set c = GetObject("WinNT://Domain")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:UserList.xls")

intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
    Username = "T" & objExcel.Cells(intRow, 1).Value

    Set u = c.Create("user", Username)
    u.Put "FullName", objExcel.Cells(intRow, 2).Value
    u.Put "Description", objExcel.Cells(intRow, 3).Value
    u.SetInfo

    Set objUser = GetObject("WinNT://Domain/" & Username)
    objUser.SetPassword(Username)

    Set oGroup = c.GetObject("Group", "NewGroup")
    oGroup.Add ("WinNT://Domain/" & Username)
    oGroup.SetInfo

    Set u = Nothing
    Set objUser = nothing
    Set oGroup = nothing

    intRow = intRow + 1
Loop

Set c = nothing
Set objWorkbook = nothing
objExcel.Quit
Set objExcel = nothing