For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > May 2005 > Current User









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Current User
Cam

2005-05-27, 8:55 pm

I am using the GetUserName API and want to know where the API looks to
retrieve the username.I know the documentation say "The GetUserName function
retrieves the user name of the current thread. This is the name of the user
currently logged onto the system."
Ok so where does it look. Is it in the registry? if so what hive. Any help
would be great.


Thanks
Cam


Bob Butler

2005-05-27, 8:55 pm

"Cam" <no@no.com> wrote in message
news:%23RQEx0uYFHA.2160@TK2MSFTNGP10.phx.gbl
> I am using the GetUserName API and want to know where the API looks to
> retrieve the username.I know the documentation say "The GetUserName
> function retrieves the user name of the current thread. This is the
> name of the user currently logged onto the system."
> Ok so where does it look. Is it in the registry? if so what hive.
> Any help would be great.


My assumption would be that it is just in memory somewhere. The OS has a
list of active threads with all associated information that it needs to keep
track of them and the GetUserName API function just gets it from that list.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Douglas Marquardt

2005-05-27, 8:55 pm

Hi Bob:

fwiw, I notice that an Environment variable gets set when you login,i.e.

USERNAME=myname

Perhaps it just reads that.

Doug.

"Bob Butler" <tiredofit@nospam.com> wrote in message news:eL5Af6uYFHA.4036@tk2msftngp13.phx.gbl...
> "Cam" <no@no.com> wrote in message
> news:%23RQEx0uYFHA.2160@TK2MSFTNGP10.phx.gbl
>
> My assumption would be that it is just in memory somewhere. The OS has a
> list of active threads with all associated information that it needs to keep
> track of them and the GetUserName API function just gets it from that list.
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>



Bob Butler

2005-05-27, 8:55 pm

"Douglas Marquardt" <no_spam@dummy.com> wrote in message
news:%23T7MBcvYFHA.1412@TK2MSFTNGP12.phx.gbl
> Hi Bob:
>
> fwiw, I notice that an Environment variable gets set when you
> login,i.e.
>
> USERNAME=myname
>
> Perhaps it just reads that.


IIRC, you can change the variable value and the API still returns the
correct name; that's the main reason why the variable is not reliable.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Bob Butler

2005-05-27, 8:55 pm

"Douglas Marquardt" <no_spam@dummy.com> wrote in message
news:%23T7MBcvYFHA.1412@TK2MSFTNGP12.phx.gbl
> Hi Bob:
>
> fwiw, I notice that an Environment variable gets set when you
> login,i.e.
>
> USERNAME=myname
>
> Perhaps it just reads that.


just to confirm that it doesn't:

Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
ByRef nSize As Long) As Long
Private Declare Function GetEnvironmentVariable Lib "kernel32" _
Alias "GetEnvironmentVariableA" (ByVal lpName As String, _
ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function SetEnvironmentVariable Lib "kernel32" _
Alias "SetEnvironmentVariableA" (ByVal lpName As String, _
ByVal lpValue As String) As Long

Private Sub Main()
Dim sName As String
Dim x As Long
Dim n As Long
x = SetEnvironmentVariable("USERNAME", "test")
sName = Space$(32)
x = GetEnvironmentVariable("USERNAME", sName, Len(sName))
Debug.Print "GEV=" & sName
sName = Space$(32)
n = Len(sName)
x = GetUserName(sName, n)
Debug.Print "GUN=" & sName
End Sub

I get:
GEV=test
GUN=bob


--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Douglas Marquardt

2005-05-29, 3:55 am

Hi Bob:

No need to confirm.... I believed ha ;-)

Doug.

"Bob Butler" <tiredofit@nospam.com> wrote in message news:evgovywYFHA.3516@TK2MSFTNGP10.phx.gbl...
> "Douglas Marquardt" <no_spam@dummy.com> wrote in message
> news:%23T7MBcvYFHA.1412@TK2MSFTNGP12.phx.gbl
>
> just to confirm that it doesn't:
>
> Private Declare Function GetUserName Lib "advapi32.dll" _
> Alias "GetUserNameA" (ByVal lpBuffer As String, _
> ByRef nSize As Long) As Long
> Private Declare Function GetEnvironmentVariable Lib "kernel32" _
> Alias "GetEnvironmentVariableA" (ByVal lpName As String, _
> ByVal lpBuffer As String, ByVal nSize As Long) As Long
> Private Declare Function SetEnvironmentVariable Lib "kernel32" _
> Alias "SetEnvironmentVariableA" (ByVal lpName As String, _
> ByVal lpValue As String) As Long
>
> Private Sub Main()
> Dim sName As String
> Dim x As Long
> Dim n As Long
> x = SetEnvironmentVariable("USERNAME", "test")
> sName = Space$(32)
> x = GetEnvironmentVariable("USERNAME", sName, Len(sName))
> Debug.Print "GEV=" & sName
> sName = Space$(32)
> n = Len(sName)
> x = GetUserName(sName, n)
> Debug.Print "GUN=" & sName
> End Sub
>
> I get:
> GEV=test
> GUN=bob
>
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>



Douglas Marquardt

2005-05-29, 3:55 am

That should be 'ya', not 'ha'.


"Douglas Marquardt" <no_spam@dummy.com> wrote in message news:emwzdK%23YFHA.2664@TK2MSFTNGP15.phx.gbl...
> Hi Bob:
>
> No need to confirm.... I believed ha ;-)
>
> Doug.
>
> "Bob Butler" <tiredofit@nospam.com> wrote in message news:evgovywYFHA.3516@TK2MSFTNGP10.phx.gbl...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com