.net 提取/获取windows用户名
如何从windows提取/获取当前用户名?.net 提取/获取windows用户名,.net,vb.net,winforms,.net,Vb.net,Winforms,如何从windows提取/获取当前用户名? 这就是我所尝试的: Dim username As String = Application.ExecutablePath.ToString.Split("\")(0) If username <> "" then MsgBox(username) End if Dim username As String=Application.ExecutablePath.ToString.Split(“\”)(0) 如果用户名为“”,则 MsgBo
这就是我所尝试的:
Dim username As String = Application.ExecutablePath.ToString.Split("\")(0)
If username <> "" then
MsgBox(username)
End if
Dim username As String=Application.ExecutablePath.ToString.Split(“\”)(0)
如果用户名为“”,则
MsgBox(用户名)
如果结束
您可以通过以下方法获取用户名:
声明函数:
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer
方法:
职能:
使用:
GetUserName函数检索与当前线程关联的用户的名称
以及其他方法:
第一: 第二:
Dim username2 As String = SystemInformation.UserName
不可取的方法:
MessageBox.Show(Application.ExecutablePath.ToString.Split("\")(2))
(你非常接近,干得好。)
不要使用msgbox()。
msgbox用于Visual Basic 6。
MessageBox.Show是用于vb.net的您也可以使用它来获取用户名:
Dim username As String =
Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)("USERNAME")
如果导入了
System.Windows.Forms
Dim username As String = SystemInformation.UserName
MessageBox.Show(Application.ExecutablePath.ToString.Split("\")(2))
Dim username As String =
Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)("USERNAME")
Dim username As String = SystemInformation.UserName