Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this message"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..."
Post Follow-up to this messageHi 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 ke ep > 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..." >
Post Follow-up to this message"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..."
Post Follow-up to this message"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..."
Post Follow-up to this messageHi 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..."
>
Post Follow-up to this messageThat should be 'ya', not 'ha'. "Douglas Marquardt" <no_spam@dummy.com> wrote in message news:emwzdK%23YFHA.2664@TK2MSFTNGP 15.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... > >
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.