曾經看過國外有人是使用 api 的方式 Get Current Username
http://www.developerfusion.com/code/4409/get-current-username-in-vbnet/
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer
Public Function GetUserName() As String
Dim iReturn As Integer
Dim userName As String
userName = New String(CChar(" "), 50)
iReturn = GetUserName(userName, 50)
GetUserName = userName.Substring(0, userName.IndexOf(Chr(0)))
End Function
.net 底下就不用那麼麻煩了
Environment.UserName '一行搞定
請參考MSDN Library / Environment 類別
沒有留言:
張貼留言