Home All Groups Group Topic Archive Search About
Author
27 May 2005 6:52 PM
Cam
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

Author
27 May 2005 7:02 PM
Bob Butler
"Cam" <n*@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..."
Author
27 May 2005 8:02 PM
Douglas Marquardt
Hi Bob:

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

USERNAME=myname

Perhaps it just reads that.

Doug.

Show quoteHide quote
"Bob Butler" <tiredofit@nospam.com> wrote in message news:eL5Af6uYFHA.4036@tk2msftngp13.phx.gbl...
> "Cam" <n*@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..."
>
Author
27 May 2005 8:37 PM
Bob Butler
"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..."
Author
27 May 2005 10:37 PM
Bob Butler
"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..."
Author
29 May 2005 12:09 AM
Douglas Marquardt
Hi Bob:

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

Doug.

Show quoteHide quote
"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
> > 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..."
>
Author
29 May 2005 12:33 AM
Douglas Marquardt
That should be 'ya', not 'ha'.


Show quoteHide quote
"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...
> > "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..."
> >
>
>