VB获取本地用户列表 [英] VB Getting list of local users

查看:86
本文介绍了VB获取本地用户列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取所有本地用户的方法.如果我只是转到用户文件夹不适,请获取本地用户和域用户.有没有办法只获取本地用户.

I need way of getting all local users. If i just go to the users folder ill get the local users and the domain users. Is there a way to get only the local users.

我要的是名字.

推荐答案

您需要添加对System.DirectoryServices的引用才能使用此功能...

You need to add a reference to System.DirectoryServices to be able to use this function...

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim Users As List(Of String) = GetLocalUsers("localhost")

    For Each User As String In Users
        MessageBox.Show(User)
    Next
End Sub

Private Function GetLocalUsers(ByVal MachineName As String) As List(Of String)
    Dim WinNt As New DirectoryServices.DirectoryEntry("WinNT://" & MachineName)
    Dim UserList As New List(Of String)

    For Each User As DirectoryServices.DirectoryEntry In WinNt.Children
        If User.SchemaClassName = "User" Then
            UserList.Add(User.Name)
        End If
    Next

    Return UserList
End Function

这篇关于VB获取本地用户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆