optom
09-09-2009, 07:45 AM
Is there a simple way to get the pc user name from VB?
Host PC Nameoptom 09-09-2009, 07:45 AM Is there a simple way to get the pc user name from VB? kassyopeia 09-09-2009, 09:28 AM Simple & unreliable: Environ$() (msdn.microsoft.com/en-us/library/aa262730%28VS.60%29.aspx) with the appropriate variable name (open a DOS prompt and type "set" to get a listing) Less simple, more reliable: GetComputerName / GetUserName Roger_Wgnr 09-10-2009, 01:00 AM Here is a sample of how to use GetComputerName. Private Declare Function GetComputerName Lib "kernel32" _ Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Public Function ComputerName() As String 'return the name of the computer Dim tmp As String 'Max of 15 characters in a Computer name + a Null terminator tmp = Space$(16) If GetComputerName(tmp, Len(tmp)) <> 0 Then ComputerName = TrimNull(tmp) Else ComputerName = "" End If End Function Private Function TrimNull(item As String) Dim pos As Integer pos = InStr(item, Chr$(0)) If pos Then TrimNull = Left$(item, pos - 1) Else TrimNull = item End If End Function |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum