WinForm(VB.NET)获取当前登录的用户名

运行Windows Task Manager,查看Users标签,可以看到所有登录电脑的用户,现在Insus.NET想命名用VB.NET的WinForm程序去获取当前的用户名.
WinForm(VB.NET)获取当前登录的用户名_第1张图片

 

获取程序简单,可以参考之:

 

源代码:

 Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer
        Public Shared Function GetUserName() As String
            Dim buffer As String = New String(CChar(" "), 50)
            Dim retVal As Integer = GetUserName(buffer, 50)
            Return Strings.Left(buffer, InStr(buffer, Chr(0)) - 1)
        End Function
View Code



 

你可能感兴趣的:(WinForm(VB.NET)获取当前登录的用户名)