welcome to 's blog...


公告

我的分类(专题)

日志更新

最新评论

留言板

链接

搜索


Blog信息




半夜写脚本scripting
aku1 发表于 2008-11-13 0:15:42

马上近100台server过来,要建帐号,估计得我写脚本了,只好把它写完了,没来得及优化

Dim arrFileLines() ,n
i = 0
Const ForReading = 1
strInputFile="C:\BAU_Users.txt"
Set FSO=CreateObject("Scripting.FileSystemObject")
Set objFile=FSO.OpenTextFile(strInputFile,ForReading)
' get local computer name
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

' Create pcAnywhere_users group
Set colAccounts = GetObject("WinNT://" & strComputer & "")
    colAccounts.Filter = Array("group")
 
' check if local group already exists
For Each objGroup In colAccounts
    If objGroup.Name = pcAnywhere_users Then
     intExists = 2
  End If
Next

Set objGroup = colAccounts.Create("group", "pcAnywhere_users")
objGroup.SetInfo

Do Until objFile.AtEndOfStream
         Redim Preserve arrFileLines(i)
     arrFileLines(i) = objFile.ReadLine
     i = i + 1

loop


objFile.Close

' specify account to create
For n = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
 
    strAccount =arrFileLines(n)
    strPswd = "viso1234"
 

' check if local account already exists
intExists = 0

colAccounts.Filter = Array("user")
For Each objUser In colAccounts
    If objUser.Name = strAccount Then
     intExists = 1
  End If
 
Next


If intExists = 0 and n <9 Then
   ' create local user
 
   Set objUser = colAccounts.Create("user", strAccount)


   ' set pswd
   objUser.SetPassword strPswd
   objUser.SetInfo


  
   ' Must change pswd next login
 
   objUser.PasswordExpired = 1
   objUser.SetInfo


   ' add to local admins group
   Set objGroup = GetObject("WinNT://" & strComputer & _
"/Administrators,group")
   Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount & _
",user")
   objGroup.Add(objUser.ADsPath)
 ' Add to pcAnywhere_users group 
   Set objGroup = GetObject("WinNT://" & strComputer & _
"/pcAnywhere_users,group")
   Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount & _
",user")
   objGroup.Add(objUser.ADsPath)
  
   else
   
   Set objUser = colAccounts.Create("user", strAccount)


   ' set pswd
   objUser.SetPassword strPswd
   objUser.SetInfo


   ' Must change pswd next login
 
   objUser.PasswordExpired = 1
   objUser.SetInfo


 ' Add to pcAnywhere_users group 
   Set objGroup = GetObject("WinNT://" & strComputer & _
"/pcAnywhere_users,group")
   Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount & _
",user")
   objGroup.Add(objUser.ADsPath)
End If
Next


 


阅读全文 | 回复(0) | 引用通告 | 编辑


发表评论:

    昵称:
    密码: (游客无须输入密码)
    主页:
    标题:



Powered by Oblog.