Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Current User
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



Report this thread to moderator Post Follow-up to this message
Old Post
Cam
05-28-05 01:55 AM


Re: Current User
"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..."


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
05-28-05 01:55 AM


Re: Current User
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 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..."
>



Report this thread to moderator Post Follow-up to this message
Old Post
Douglas Marquardt
05-28-05 01:55 AM


Re: Current User
"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..."


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
05-28-05 01:55 AM


Re: Current User
"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..."


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
05-28-05 01:55 AM


Re: Current User
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..."
>



Report this thread to moderator Post Follow-up to this message
Old Post
Douglas Marquardt
05-29-05 08:55 AM


Re: Current User
That 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... 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Douglas Marquardt
05-29-05 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:38 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.