運行Windows Task Manager,查看Users標簽,可以看到所有登錄電腦的用戶,現在Insus.NET想命名用VB.NET的WinForm程式去獲取當前的用戶名. 獲取程式簡單,可以參考之: 源代碼: Declare Function GetUserName Lib "advapi32
運行Windows Task Manager,查看Users標簽,可以看到所有登錄電腦的用戶,現在Insus.NET想命名用VB.NET的WinForm程式去獲取當前的用戶名.
源代碼:
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 FunctionView Code