Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Windows User Name 1

Status
Not open for further replies.

ALS

Programmer
Oct 16, 1998
5
0
0
DE
How can I get the actual Windows User-Name on a NT4.0 and WIN95 PC<br>
in a Text variable ?<br>
I need the User including the Domain-Name.
 
you have to use the win32 api to retrieve that info. Do you have any experience with the Windows API? If not I can recommend a book called Visual Basic 5.0 programmers guide to the Win32 API. You would need to set up a module with the getusername function. And call the function from your form with a button click event or other event of your choice. You can run the apiload.exe in your \devstudio\vb\winapi\ directory. This way you can view the necessaries of the getusername api. Need anymore clues post away...<br>
<br>
pos<br>

 
Try this declaration in the declarations sections of a module<br>
<br>
Declare Function WNetGetUser Lib "advapi32.dll" Alias "GetUserNameA" (ByVal szUser$, lpnBufferSize%) As Long<br>
<br>
and call it like this:<br>
<br>
dim uname as string, len as integer<br>
call GetUserNameA(uname,len)<br>
<br>
uname should be set to the user name<br>
<br>
Mike<br>

 
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long<br>
Function ClipNull(InString As String) As String<br>
<br>
Dim intpos As Integer<br>
<br>
If Len(InString) Then<br>
intpos = InStr(InString, vbNullChar)<br>
If intpos &gt; 0 Then<br>
ClipNull = Left(InString, intpos - 1)<br>
Else<br>
ClipNull = InString<br>
End If<br>
End If<br>
<br>
End Function<br>
Function GetUser() As String<br>
<br>
Dim lpUserID As String<br>
Dim nBuffer As Long<br>
Dim Ret As Long<br>
lpUserID = String(25, 0)<br>
nBuffer = 25<br>
Ret = GetUserName(lpUserID, nBuffer)<br>
<br>
If Ret Then<br>
GetUser$ = lpUserID$<br>
End If<br>
<br>
End Function<br>
'Call like this<br>
dim strUser as string<br>
strUser = ClipNull(GetUser())
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top