dbTalk Databases Forums  

Getting Windows user name

comp.database.ms-access comp.database.ms-access


Discuss Getting Windows user name in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mike Turco
 
Posts: n/a

Default Getting Windows user name - 08-31-2004 , 03:07 AM






Lets say that my WinXP computer has two users: Michael and Kathryn. One or
the other logs into the computer and opens up an Access database (I happen
to be using 2002). There is no security on the database -- just click on the
shortcut and you're in.

I want to be able to determine who opened that database by knowing who
logged into the computer.

Is there a way to get the windows user name?

I have another question, and this one may be a bit off-topic, but I'll run
it up the flagpole.

I want to leave the above-named database open all the time, such that
whenever anybody logs in at the windows login screen, the database will be
up and running. In the actual application there may be as many as twenty
people accessing the same application, and I don't want twenty instances of
the program running -- one for each user. Can I have that database display
on the screen of all users? (Specifically, I would like to use Windows Fast
User Switching to change users.)

In most situations, I could resolve these issues using Access' security
features. This is a unique application, though, and the users won't be able
to log into the database themselves.

Thanks!

Mike



Reply With Quote
  #2  
Old   
Rob
 
Posts: n/a

Default Re: Getting Windows user name - 09-04-2004 , 03:43 PM






Mike, I had to build a database recently that needed to know who was
logged in. Create a module and place this in the declarations section:

**************************************
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long
**************************************

Then create a function that looks something like this:

**************************************
Function GetUser() As String

' Procedure: GetUser()
' Modified: 26 Aug 2004 RAM
' Purpose: Necessary Function for WINAPI Function, GetUserName
' Input: N/A
' Output: GetUser$

Dim lpUserID As String
Dim nBuffer As Long
Dim Ret As Long

lpUserID = String(25, 0)
nBuffer = 25

Ret = GetUserName(lpUserID, nBuffer)

If Ret Then
GetUser$ = lpUserID$
End If

End Function
**************************************

When you run the GetUser() function it returns the UserID of the
person currently logged into the computer.

I hope this helps.

Rob


"Mike Turco" <miketurco (AT) yahoo-nospam4me (DOT) com> wrote

Quote:
Lets say that my WinXP computer has two users: Michael and Kathryn. One or
the other logs into the computer and opens up an Access database (I happen
to be using 2002). There is no security on the database -- just click on the
shortcut and you're in.

I want to be able to determine who opened that database by knowing who
logged into the computer.

Is there a way to get the windows user name?

I have another question, and this one may be a bit off-topic, but I'll run
it up the flagpole.

I want to leave the above-named database open all the time, such that
whenever anybody logs in at the windows login screen, the database will be
up and running. In the actual application there may be as many as twenty
people accessing the same application, and I don't want twenty instances of
the program running -- one for each user. Can I have that database display
on the screen of all users? (Specifically, I would like to use Windows Fast
User Switching to change users.)

In most situations, I could resolve these issues using Access' security
features. This is a unique application, though, and the users won't be able
to log into the database themselves.

Thanks!

Mike

Reply With Quote
  #3  
Old   
G.J. v.d. Kamp
 
Posts: n/a

Default Re: Getting Windows user name - 09-11-2004 , 08:35 AM



I always use strUser = Environ("username")

Regards GJ



google (AT) pinnaclepromos (DOT) com (Rob) wrote in message news:<85d3bc52.0409041243.1bd67558 (AT) posting (DOT) google.com>...
Quote:
Mike, I had to build a database recently that needed to know who was
logged in. Create a module and place this in the declarations section:

**************************************
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long
**************************************

Then create a function that looks something like this:

**************************************
Function GetUser() As String

' Procedure: GetUser()
' Modified: 26 Aug 2004 RAM
' Purpose: Necessary Function for WINAPI Function, GetUserName
' Input: N/A
' Output: GetUser$

Dim lpUserID As String
Dim nBuffer As Long
Dim Ret As Long

lpUserID = String(25, 0)
nBuffer = 25

Ret = GetUserName(lpUserID, nBuffer)

If Ret Then
GetUser$ = lpUserID$
End If

End Function
**************************************

When you run the GetUser() function it returns the UserID of the
person currently logged into the computer.

I hope this helps.

Rob


"Mike Turco" <miketurco (AT) yahoo-nospam4me (DOT) com> wrote

Lets say that my WinXP computer has two users: Michael and Kathryn. One or
the other logs into the computer and opens up an Access database (I happen
to be using 2002). There is no security on the database -- just click on the
shortcut and you're in.

I want to be able to determine who opened that database by knowing who
logged into the computer.

Is there a way to get the windows user name?

I have another question, and this one may be a bit off-topic, but I'll run
it up the flagpole.

I want to leave the above-named database open all the time, such that
whenever anybody logs in at the windows login screen, the database will be
up and running. In the actual application there may be as many as twenty
people accessing the same application, and I don't want twenty instances of
the program running -- one for each user. Can I have that database display
on the screen of all users? (Specifically, I would like to use Windows Fast
User Switching to change users.)

In most situations, I could resolve these issues using Access' security
features. This is a unique application, though, and the users won't be able
to log into the database themselves.

Thanks!

Mike

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.