windows 使用 VBScript 创建用户帐户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/696348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:14:19  来源:igfitidea点击:

Create user account with VBScript

windowsvbscript

提问by

I'm using this code to create user account,

我正在使用此代码创建用户帐户,

Function CreateUserAccount (acc, paas)

函数 CreateUserAccount (acc, paas)

 Dim WinUserAccountName, WinUserAccountPass

 WinUserAccountName = Session.Property("WIN_USER_ACCOUNT")
 WinUserAccountPass = Session.Property("WIN_USER_PASS")

 strComputer = "."
 set objSystem = GetObject("WinNT://" & strComputer)
 set objUser = objSystem.Create("user", WinUserAccountName)
 objUser.SetPassword WinUserAccountPass
 objUser.SetInfo

End Function

结束函数

It works OK so far, the only thing I need to implement is:

到目前为止它工作正常,我唯一需要实现的是:

  1. When the user name is already in the machine. Display message to the user telling him/her that this user name is already exist.
  1. 当用户名已经在机器中时。向用户显示消息,告诉他/她该用户名已存在。

How can I do that in VBScript? Is there error code I can catch?

我怎样才能在 VBScript 中做到这一点?有我可以捕获的错误代码吗?

Thanks,

谢谢,

回答by

OK, I found the script I was looking for:

好的,我找到了我正在寻找的脚本:

QueryForUser("kenmyer")
Wscript.Echo "This user account does not exist."

Sub QueryForUser(strUserName)
    strComputer = "."
    Set objDomain = GetObject("WinNT://" & strComputer)
    objDomain.Filter = Array("user")
    For Each User In objDomain
        If lcase(User.Name) = lcase(strUserName) Then
            WScript.Echo User.Name & " already exists."
            WScript.Quit
        End If    
    Next
End Sub