使用输入框返回ActiveDirectory信息

时间:2011-05-20 14:03:16

标签: vb.net visual-studio-2010 active-directory

我有以下代码,因此用户可以在程序运行之前输入他们的域。 生成的文本文件不会输出用户..只需单词Schema ...

编辑1:更新以包含所有代码。我现在可以运行它,它返回一个列出的文本文件 OU = _USERS OU = _GROUPS OU = _etc ETC等

Sub PrintUserNames()
    'Declare Command
    Dim de As New DirectoryEntry()
    'Nameint Place to Write file
    Dim userFile As String = "C:\DomainUsers.txt"
    Dim fileExists As Boolean = File.Exists(userFile)

    'Use Input Box for domain entry
    Dim message, Title, defaultValue As String
    Dim myValue As Object
    message = "Enter your Domain Name"
    Title = "Domain Name Entry"
    defaultValue = "Enter Domain Name"
    myValue = InputBox(message, Title, defaultValue)
    'Get List of all users on Domain using WinNT
    'Replacement Command
    Dim ReplaceCommand1 As String = de.Path.Replace("***", myValue) = "WinNT://""***"""
    Using sw As New StreamWriter(File.Open(userFile, FileMode.OpenOrCreate))
        For Each d As DirectoryEntry In de.Children()
            sw.WriteLine(d.Name)
        Next
    End Using

2 个答案:

答案 0 :(得分:0)

在您(重新)分配之前,您正在替换占位符***

Dim ReplaceCommand1 As String = de.Path.Replace("***", myValue)
de.Path = "WinNT://***"

根据您创建de的位置,您只需删除包含de.Path = "WinNT://***"

的行即可

答案 1 :(得分:0)

感谢提示Filburt。 我只是扔掉了实际上正在制作替换命令并使用它,如下所示。

Dim de As New DirectoryEntry()
    Dim DomainName As Object
    'Use Input Box for domain entry if desired   
    Dim messageOK, messageCan, Title, defaultValue As String
    messageOK = "Enter Domain and Click OK
    Title = "Domain Name Entry"
    defaultValue = "Enter Domain Name"
    DomainName = InputBox(messageOK, Title, defaultValue)
    de.Path = "WinNT://***".Replace("***", DomainName)