473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

NT User Name returns profile name "USER"

MMcCarthy
14,534 Expert Mod 8TB
Hi everyone

I had an interesting problem today with a client.

I have set up security and privilege on a database depending on NT User Login. However, I've only just realised that the code returns the profile name and not the login name. This company has the profile name "USER" generic to its profiles for some strange reason. It may be a group issue, I'm not network savvy.

Does anyone know of a way of retrieving the actual login name.

The code I am using is the standard code as below ...

Expand|Select|Wrap|Line Numbers
  1. Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
  2.  
  3. Function sys_OrigUserID() As String
  4. On Error GoTo Err_sys_OrigUserID
  5. ' Returns the username of the current logged in user.
  6. Dim s$, cnt&, dl&
  7. Dim max_String As Integer
  8. Dim usename As String
  9.  
  10.     max_String = 30
  11.     cnt& = 199
  12.     s$ = String$(max_String, 1)
  13.     dl& = GetUserName(s$, cnt)
  14.     usename = Trim$(left$(s$, cnt))
  15.     usename = UCase(Mid(usename, 1, Len(usename) - 1))
  16.     sys_OrigUserID = usename
  17.  
  18. Exit_sys_OrigUserID:
  19. Exit Function
  20. Err_sys_OrigUserID:
  21.     Select Case Err
  22.     Case 0      '.insert Errors you wish to ignore here
  23.         Resume Next
  24.     Case Else   '.All other errors will trap
  25.         Beep
  26.         MsgBox Err.Description, , "Error in Function SystemCode.sys_OrigUserID"
  27.         Resume Exit_sys_OrigUserID
  28.     End Select
  29.     Resume 0    '.FOR TROUBLESHOOTING
  30. End Function
  31.  
Oct 15 '07 #1
8 3031
nico5038
3,080 Expert 2GB
Did you try:
Environ("username")

Nic;o)
Oct 15 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
Did you try:
Environ("username")

Nic;o)
You mean change

sys_OrigUserID = username

to

sys_OrigUserID = Environ("username")
Oct 15 '07 #3
nico5038
3,080 Expert 2GB
Yes, I don't even use a function, just this Environ() function "straight away".
It can be used for all systemvariables available on the computer, so also:
Environ("computername")

Nic;o)
Oct 15 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
Yes, I don't even use a function, just this Environ() function "straight away".
It can be used for all systemvariables available on the computer, so also:
Environ("computername")

Nic;o)
Thanks Nico

I've never tried using it in this way. I'll test it out.

Mary
Oct 15 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
OK I've tested it and Environ seems to give the account name rather than the profile name which is what I need. I won't know for sure until I test it onsite and that won't be until next week but looking good.

Thanks Nico.

Mary
Oct 15 '07 #6
Jim Doherty
897 Expert 512MB
OK I've tested it and Environ seems to give the account name rather than the profile name which is what I need. I won't know for sure until I test it onsite and that won't be until next week but looking good.

Thanks Nico.

Mary
Supplemental to Nico Mary, look at this helpful wiki page you can reference the olther variables not just username to return what you need ie:userdomain,logonserver etc etc

http://en.wikipedia.org/wiki/Environment_variable

Jim
Oct 17 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Supplemental to Nico Mary, look at this helpful wiki page you can reference the olther variables not just username to return what you need ie:userdomain,logonserver etc etc

http://en.wikipedia.org/wiki/Environment_variable

Jim
Thats great Jim.

Thank you very much.
Oct 17 '07 #8
questionit
553 512MB
Hi
There are many system and user variables in windows that can be used in Access with Environ()

If you do this:

1. Right click My Computer and then click Properties.
2. Click the Advanced tab.
3. Click Environment variables.

You will see the available variables.

You can use them in Command Prompt to read thier values.
In command prompt type: echo %Variable-Name%

For example: echo %OS%

Regards
Qi

Thats great Jim.

Thank you very much.
Oct 17 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jissay | last post by:
Hi, I use the following scrit in an Intranet with the user name = "" and the password = "" : <?php $ftp_server = "192.168.25.25"; $ftp_user = ""; $ftp_pass = "";
4
by: Henro V | last post by:
I want the login name that somebody enters when starting the database to be set as a variable. I'll try to explain: I have a table (Engineer) that lists engineers (they are the users) The...
0
by: Rob | last post by:
I need to allow a user with the default "Full Data User" permissions on the front-end database to relink to a table in a backend to which he has the same permissions. (I'd like to do read, update,...
1
by: platinumbay | last post by:
Sometimes when I run or build (or save I think) one of several VB .NET CE applications I get the above error. I then get a 'save file as' option to change the 'myapp.vbdproj' file. If you keep the...
4
by: Ying Lu | last post by:
Hello, I have a table named "USER" under MySQL database. When I am trying to move tables from MySQL to PostgreSQL, I found that I could not create a table namely "USER". I guess "USER" is a key...
5
by: mabond | last post by:
Hi all This question is one of "theory" rather than a search for the specifics of a solution. I need some pointers as to how to proceed with my project. Here goes. My application allows the...
2
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
I have a .NET 1.1 component trying to connect to a database but I keep getting the following message when the exception is thrown: @"Login failed for user '\'." It appears that no user and...
5
by: WP | last post by:
Hello, I need to communicate with a db2 database from a java program and this java program needs to check which "user tables" there are. I came up with the following query which I tried in Control...
11
by: fniles | last post by:
One of our application uses VB6 and Access97 database. Another application uses VB.NET 2005. This morning for about 15 seconds when the application tries to read either a query or a table from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.