Solved

Get Microsoft Access 2007 user from laccdb or get username from Computer Name

Posted on 2013-01-28
47
1,983 Views
Last Modified: 2013-02-14
I would like to get the username for users logged on to an Access 2007 database (.accdb) on the network. Could do it with ldbviewer or opening ldb file with Notepad in earlier versions of Access but it doesn't work with .laccdb files.
Apparently, .laccdb files are in binary format. I can get the computer name of users in Access 2007 files. That would work if I could get the username from the computer name.
So I'm looking for either getting the username from .laccdb files or corresponding the username from the computer name. Seems like net view should help but hasn't worked for me so far.
I tried oWMIService too, but it didn't work for me. I don't have Network Adiministration privileges.
Any help is greatly appreciated.
0
Comment
Question by:Concentus
  • 23
  • 18
  • 5
  • +1
47 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
Comment Utility
EE's datAdrenaline -works with A2007/10.
http://www.experts-exchange.com/Database/Miscellaneous/Q_25075096.html

See the Accepted Solution.  I have confirmed this works (in A2007/2010)
mx
0
 

Author Comment

by:Concentus
Comment Utility
DatabaseMX,
Thanks. I think that's really close to what I need (maybe as close as I can get). But, unfortunately, in the "Windows User" column it says "Unable to acquire" for users other than myself. Might be a security rule configured on our Network.

Looks like this utility uses a WMI Service object to get the user. I think I need some alternative method for getting the username from the computer name.

It's a great tool; hope i can tweak something to make it work for me, though.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Well of course this is this:

dim x
x=Environ("UserName")

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"Might be a security rule configured on our Network. "
Odd.  When I tested, I tested on our corp network.

This is also this - preferred over Environ() :

http://access.mvps.org/access/api/api0008.htm
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
OOPS ... sorry ... ignore last two posts.  Not for finding out who is in ACCDB ...

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Although not free like the LDB Viewer, if you want a tool with a LOT more functionality you might be interested in this product (which I have):

http://www.fmsinc.com/MicrosoftAccess/monitor.asp

Unfortunately, a lot of viewers that worked with LDB's were not upgraded to work with ACCDB's
0
 

Author Comment

by:Concentus
Comment Utility
Thanks DatabaseMX. I might have to try to upgrade to the newer fmsinc utility (I bought an earlier version - 2000 version, I believe. Good chance they use WMI Service too, though. Looks like that's the standard way of getting the username.
Our network administrators seem to have things wrapped up pretty tight. Which I understand, but it makes some things pretty difficult sometimes. I think there is something that keeps one user from seeing the user of another computer. Might be something that just keeps the users from getting their PC hacked but the unintended consequences is that the WMI Service can't relay the username to another component.
0
 

Author Comment

by:Concentus
Comment Utility
Even if I have to do it manually, it's better than nothing. I found that I can read some of the .laccdb file with MS Word (plus the utility you directed me to, does show the computer name). It shows the computer name, but not the username.
I tried to figure out how to get it by using command line "net view" but the syntax seems a bit abstract. I'm not even sure if it's possible.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"laccdb file with MS Word"
I've noticed at times however, when I opened an LDB file ... it's unreadable.

"I think there is something that keeps one user from seeing the user of another computer."
Well, I don't think that would prevent getting into an lock ('laccdb) file.

I don't know if FMS is using WMI or not ? I also use TAA.  I will email Luke and point him to this Q ... standby ...

mx
0
 
LVL 10

Expert Comment

by:LukeChung-FMS
Comment Utility
Hi mx,

Thanks for mentioning Total Access Admin. Unfortunately, we only show what's in the LDB which shows the machine name. and don't go beyond that. I'm not sure there's enough information to get from the machine name to the user name, since multiple logins can occur from the same machine.

A feature of Total Access Admin is that it can log into a table (in an Access database) all the activity of users connecting and disconnecting from your database. If you can associate machines to specific users, a simple table and query would link the two.

I'm not familiar with WMI. Will that reveal the current user logged in from a particular machine? I presume you'd need Admin rights to see that.
0
 

Author Comment

by:Concentus
Comment Utility
Hi Luke, mx,

I hadn't actually used it myself, but this is the bit of code that is returning "Unable to aquire." for me in the WhoisConnected utility:
 
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
...
   If objWMIService Is Nothing Then
        strName = "Unable to aquire."
        strDomain = "Unable to aquire."
    Else
        'Get the computer as a collection.
        Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
        'Set the remote user name
        For Each objComputer In colComputer
            strTemp = strTemp & "|" & objComputer.UserName
        Next... 

Open in new window


Seems like a really good tool - it's just not working for me. I don't know if it requires admin privileges or if it's a configuration on our network.

Thanks for looking at this.
0
 

Author Comment

by:Concentus
Comment Utility
...also, it does show my username. Just no one else's. That's what makes me suspect a security-related configuration.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"I presume you'd need Admin rights to see that."

Apparently not ... because we no longer have Local Admin Rights on Win7 machines ... but what Brent posted  Here  does work.
0
 

Author Comment

by:Concentus
Comment Utility
I notice that TAA shows a username column

Monitor-Database image

but it looks like the value, basically, is the same as that which would be returned by Application.CurrentUser which gives the user name stored in the workgoup file on secured databases. I think that if a database is not secured via workgroup security (which isn't available in Access 2007) the default login is "Admin" (because the default user permissions is admin). I think this is the value stored in the lock file.

Some utilities appear to use WMI in conjuction with the computer name retrieved from the lock file to show the network username.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
".also, it does show my username. Just no one else's."
That is REALLY odd.

Let me Ping Brent also ...

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Actually ..
" That would work if I could get the username from the computer name. "

Do you mean the Real Name (like Bobbi Jo User) of the person - related to the DeviceID in the laccdb file ?

mx
0
 

Author Comment

by:Concentus
Comment Utility
Thanks for all your help. I will be in route for a few hours but will check back in asap...
0
 

Author Comment

by:Concentus
Comment Utility
Hey, i just noticed your newer responses.

It is odd. Seems to be fairly unique to my situation. We have pretty tight security on our network. That's what I suspect. But we could get the username before we upgraded form Access 2003.

...

I mean user name, like the network user ID used to logon to the network domain.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
OK ... so, you want to determine the Windows logged on User Name from the DeviceIDs contained in the laccdb, is that correct ?

mx
0
 

Author Comment

by:Concentus
Comment Utility
Yes, that's it.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
ok ... I have some code that will return the Actual real name of the person (like Bobbie Jo Blues) that related to a DeviceID found in the LACCDB.   You can pass it the DeviceID.
Standby ...

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
ok ... I've tested this code on our network and it returns my real name. BUT ... It's not quite what I thought - which was I thought you could pass the DeviceID (Optionally). But instead, you can pass the Windows Logged On User Name - same as you would get from Environ("ComputerName"), etc.

So ... not quite there yet ...
I will ping Brent and see if he knows.


Option Compare Database
Option Explicit


Private Type ExtendedUserInfo
    EUI_name As Long
    EUI_password  As Long '  Null, only settable
    EUI_password_age  As Long
    EUI_priv  As Long
    EUI_home_dir  As Long
    EUI_comment  As Long
    EUI_flags  As Long
    EUI_script_path  As Long
    EUI_auth_flags  As Long
    EUI_full_name As Long
    EUI_usr_comment  As Long
    EUI_parms  As Long
    EUI_workstations  As Long
    EUI_last_logon  As Long
    EUI_last_logoff  As Long
    EUI_acct_expires  As Long
    EUI_max_storage  As Long
    EUI_units_per_week  As Long
    EUI_logon_hours  As Long
    EUI_bad_pw_count  As Long
    EUI_num_logons  As Long
    EUI_logon_server  As Long
    EUI_country_code  As Long
    EUI_code_page  As Long
End Type
 
 'Windows API function declarations
Private Declare Function apiNetGetDCName Lib "netapi32.dll" _
Alias "NetGetDCName" (ByVal servername As Long, _
ByVal DomainName As Long, _
bufptr As Long) As Long
 
 ' function frees the memory that the NetApiBufferAllocate function allocates.
Private Declare Function apiNetAPIBufferFree Lib "netapi32.dll" _
Alias "NetApiBufferFree" (ByVal buffer As Long) As Long
 
 ' Retrieves the length of the specified Unicode string.
Private Declare Function apilstrlenW Lib "kernel32" _
Alias "lstrlenW" (ByVal lpString As Long) As Long
 
Private Declare Function apiNetUserGetInfo Lib "netapi32.dll" _
Alias "NetUserGetInfo" (servername As Any, _
username As Any, _
ByVal level As Long, _
bufptr As Long) As Long
 
 ' moves memory either forward or backward, aligned or unaligned,
 ' in 4-byte blocks, followed by any remaining bytes
Private Declare Sub sapiCopyMem Lib "kernel32" _
Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, _
ByVal Length As Long)
 
Private Declare Function apiGetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 
Private Const MAXCOMMENTSZ = 256
Private Const NERR_SUCCESS = 0
Private Const ERROR_MORE_DATA = 234&
Private Const MAX_CHUNK = 25
Private Const ERROR_SUCCESS = 0&
 
Function GetFullNameOfLoggedUser (Optional strUserName As String) As String
     '
     ' Returns the full name for a given network username (NT/2000/XP only)
     ' Omitting the argument will retrieve the full name for the currently logged on user
     '
    On Error GoTo Err_GetFullNameOfLoggedUser
    Dim pBuf As Long
    Dim dwRec As Long
    Dim pTmp As ExtendedUserInfo
    Dim abytPDCName() As Byte
    Dim abytUserName() As Byte
    Dim lngRet As Long
    Dim i As Long
     
     ' Unicode
    abytPDCName = GetDCName() & vbNullChar
    If (Len(strUserName) = 0) Then
        strUserName = GetUserName()
    End If
    abytUserName = strUserName & vbNullChar
     
     ' Level 2
    lngRet = apiNetUserGetInfo(abytPDCName(0), abytUserName(0), 2, pBuf)
    If (lngRet = ERROR_SUCCESS) Then
        Call sapiCopyMem(pTmp, ByVal pBuf, Len(pTmp))
        GetFullNameOfLoggedUser = StrFromPtrW(pTmp.EUI_full_name)
    End If
     
    Call apiNetAPIBufferFree(pBuf)
     
Exit_GetFullNameOfLoggedUser:
    Exit Function
     
Err_GetFullNameOfLoggedUser:
     MsgBox Err.Description, vbExclamation
    GetFullNameOfLoggedUser = vbNullString
    Resume Exit_GetFullNameOfLoggedUser
End Function
 
Private Function GetUserName() As String
     ' Returns the network login name
    Dim lngLen As Long, lngRet As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngRet = apiGetUserName(strUserName, lngLen)
    If lngRet Then
        GetUserName = Left$(strUserName, lngLen - 1)
    End If
End Function
 
Function GetDCName() As String
    Dim pTmp As Long
    Dim lngRet As Long
    Dim abytBuf() As Byte
     
    lngRet = apiNetGetDCName(0, 0, pTmp)
    If lngRet = NERR_SUCCESS Then
        GetDCName = StrFromPtrW(pTmp)
    End If
    Call apiNetAPIBufferFree(pTmp)
End Function
 
Private Function StrFromPtrW(pBuf As Long) As String
    Dim lngLen As Long
    Dim abytBuf() As Byte
     
     ' Get the length of the string at the memory location
    lngLen = apilstrlenW(pBuf) * 2
     ' if it's not a ZLS
    If lngLen Then
        ReDim abytBuf(lngLen)
         ' then copy the memory contents
         ' into a temp buffer
        Call sapiCopyMem(abytBuf(0), ByVal pBuf, lngLen)
         ' return the buffer
        StrFromPtrW = abytBuf
    End If
End Function
0
 

Author Comment

by:Concentus
Comment Utility
mx,
Thanks for the code. I will take a look at it. I believe that the Windows Logged On User Name is what I'm looking for. I think that's the  value in our Outlook address book "Alias" field where I can look up the employee's phone number and send email. If I have that I can contact them and ask them to close the database so I can deploy changes (I spent hours yesterday trying to get the database closed to deploy a change).
I have a couple methods for handling this, by the way. In fully developed databases, I use a form that closes down the database and I have a table that stores the network ID and datetime when they open and close the database. But sometimes, and I haven't figured out why, they both fail. So if I could use the lockfile to identify the user when these things don't work or aren't configured yet.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Concentus
Comment Utility
Looking at the code for the WhoIsConnected, I figured something out:
WMI ErrorThe reason it's not working for me is it is an error returned when trying to get the username from the computer name - "Permission Denied". I didn't catch that before because the Error object is cleared on the next line.
Anyway. Now we know why the WMI Service object isn't working the way we want it.
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
Comment Utility
Interesting - 'permission denied'.  Why is that ?

Also RE:
"If I have that I can contact them and ask them to close the database so I can deploy changes (I spent hours yesterday trying to get the database closed to deploy a change). "

You can solve that issue with Peter's (free) FSD app:
http://www.peterssoftware.com/fsd.htm

I built an entire Forced Shut Down utility which will close any and all Front End dbs open - pretty much w/o fail.  It's part of my nightly backup/compact/repair utility that we run each evening. Peter figured it all out.

mx
0
 

Author Comment

by:Concentus
Comment Utility
Thanks for the link to the FSD tool. Believe it or not, download is blocked. I'll try to look at it tonight and hopefully I can rebuild a workable solution from his as example.

Concerning 'permission denied':
I believe it's a setting/settings on our PCs. I researched this a bit and from what I can see it has to do with being able to access a remote PC (being blocked). We can't see anything on each other's PCs. I suspect there are settings in Component services or the registry that I can't access. These security issues happen so much I'm used to it. It's just a (time consuming) part of doing the job - have to find a safe work around. For this issue, looks like the best thing for me to do is to log the PC name {Environ("ComputerName")} with the Network name in the user log when they first open the DB. Then if I can't figure out any other way i can get the PC name from the lockfile and, hopefully, query out the probable user from the log.

Thanks for all your help - very much appreciate it.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
If I attach the FSD file here, can you download it?
It's really just an MDB with code and sample form, etc.
0
 

Author Comment

by:Concentus
Comment Utility
Probably not. But thanks for offering.
I should be able to look at it tonight and plug something in to my existing routine tomorrow.

My current method gives a warning to the user via vbs and uses two forms with timers. One form tests for the shutdown field to trigger the warning and then opens the other form to shutdown the database after a few minutes.

Maybe the timers are having a conflict. I'll take a look at this FSD file and try it. If I have trouble getting it to work properly, I'll post another question.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Peter figured out all of the nuances of being SURE all Forms are close, etc.  Also ... a way to take into account say if a form happens to be in a Before Update event - or other event that can be cancelled ... there is a global var you can test - to see if you should immediately exit the event - so it won't get hung up.  Stuff like that.

I really works well.

BUT ... I would still like to figure out how ... from the DeviceID in the ldb or laccdb - to extract the Win user name (and real name) from where ever.  Not sure if this can be done - w/o a cross reference table - like I have now in a config db.
0
 

Author Closing Comment

by:Concentus
Comment Utility
Thanks for all your help.

Here's a summary for anyone else who might have this same problem:

The tool Databasemx recommended in the first response would have solved my problem except, I believe, for some configuration setting unique to the network I am working on.
I found that the WMI Service object was receiving a 'permission denied' error when I added a breakpoint in the debugger and added a watch to the error object.
I believe it's a setting/settings on our PCs. I researched this a bit and from what I can see it has to do with being able to access a remote PC (being blocked). We can't see anything on each other's PCs. I suspect there are settings in Component services or the registry that I can't access. ...

For this issue, looks like the best thing for me to do is to log the PC name {Environ("ComputerName")} with the Network name in the user log when they first open the DB. Then if I can't figure out any other way i can get the PC name from the lockfile and, hopefully, query out the probable user from the log.

Also, the FSD tool recommended in the later response will help work around the issue.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"We can't see anything on each other's PCs. "
For the record, we cannot either (there are 1000's of users) except - I've noticed that there are some deviceIDs wherein some folders are shared - thus can be viewed - mostly on some 'public'  (within company) type devices.

mx
0
 
LVL 11

Expert Comment

by:datAdrenaline
Comment Utility
Adding to the conversation ... you can create the objWMIService object using credentials with permissions to interrogate remote boxes.  To do that, use something like this to create the objWMIService object in the Who's Logged on project ...

        Set objWMIService = CreateObject("WbemScripting.SWbemLocator").ConnectServer(strComputer, "root\cimv2", strUser, strPassword)
        objWMIService.Security_.ImpersonationLevel = 3
        objWMIService.Security_.AuthenticationLevel = 6

Open in new window


If you want to use this technique for the local machine, you can pass "." to strComputer and leave strUser and strPassword blank because passing credentials to interrogate the local machine with SWbenLocator will raise an error.  Also, when you pass the strUser be sure to specify the domain (ie: someDomain\someUsername), otherwise the local machine will be assumed.

So, if your IT department can set up a username and password on the domain that gives you permission to read such information, then I would suggest that you give that a whirl.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Brent .. thx for chiming in.
So ... is there any way you know of ... given a DeviceID from an LDB/LACCDB file - to extract the Windows Logged On user name from the system - short of having some sort of cross reference table, etc ?
0
 

Author Comment

by:Concentus
Comment Utility
datAdrenaline,

Thanks for the code and thanks for the suggestion. That's a great idea.
0
 
LVL 11

Expert Comment

by:datAdrenaline
Comment Utility
"So ... is there any way you know of ... given a DeviceID from an LDB/LACCDB file - to extract the Windows Logged On user name from the system"

That is what Who's Logged on does through the RemoteUser class... or am I not understanding your question.

---

Are you wanting ...
UserName (ie: bspauld)
or
FullName (ie: Brent Spaulding)

The UserName is obtainable through WMI, and that is what the RemoteUser class provides, however the FullName, if I am not mistaken, would have to be obtained through interaction with Active Directory ... which can be done too --- let me see if I can dig something up.
0
 
LVL 11

Expert Comment

by:datAdrenaline
Comment Utility
For the full active directory name, I dug up this from one of my previous projects ...

Public Function GetActiveDirectoryFullName(strDomain As String, strUsername As String) As String
    
    'Connect to Active Directory
    Dim cnn As Object 'ADODB.Connection
    Set cnn = CreateObject("ADODB.Connection")
    
    cnn.Provider = "ADsDSOObject"
    cnn.Open "Active Directory Provider"
    
    'Create the query
    Dim strSQL As String
    strSQL = "SELECT distinguishedName" & _
             " FROM 'LDAP://" & strDomain & "'" & _
             " WHERE objectCategory='user'" & _
                   " AND samAccountName = '" & strUsername & "'"

    'Get the data and return the result
    Dim rst As Object 'ADODB.Recordset
    Set rst = cnn.Execute(strSQL, , 1)

    If Not rst.EOF Then _
        GetActiveDirectoryFullName = Split(Mid(rst.Fields("distinguishedName"), Len("CN=") + 1), ",")(0)

    'Close what we open.
    rst.Close
    cnn.Close
    
End Function

Open in new window


Example:
? GetActiveDirectoryFullName("hslda", "bspauld")
Brent Spaulding
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"or am I not understanding your question."

Well ... the goal is to pass a DeviceID (aka ComputerName) - which are contained in LDB/ACCDB files ... to a function, and it returns the Windows User Name - eg 'bspauld'.  Once we have that, if desired - we can get the Full, real name (eg Brent Spaulding).  I have that code.

The LDB/LACCDB only contains ComputerNames (aka DeviceIDs) of mdb/accdb users connnected.
0
 

Author Comment

by:Concentus
Comment Utility
Thanks DatabaseMX and datAdrenaline for looking at this. I'm wondering if admin permissions are needed to query the ActiveDirectory. I will try that tomorrow.

To get the username, perhaps we would query something like (in pseudoSQL):
~"Select samAccountName ... where ... ~[Computer{table}].[name]= {DeviceID}"~
0
 

Author Comment

by:Concentus
Comment Utility
datAdrenaline,
Thanks for the Active-Directory code. Did not require any higher level permissions. This might be a way for getting the username (if I can figure out how they store the computer name).
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
The missing link:  Getting the User Name if you have the Computer Name (from LDB file)

????===????
0
 
LVL 11

Expert Comment

by:datAdrenaline
Comment Utility
the who's logged on application has that code in it, check out the remote user class in that application.

it does use WMI to accomplish that feat.  if you'd like I can post a function based sample to acquire the information desired.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
sure ... if you can.
0
 
LVL 11

Expert Comment

by:datAdrenaline
Comment Utility
Ok ... see if this does the trick.

Public Function GetUserName(Optional strComputer As String = ".", Optional ByVal strUser As String, Optional ByVal strPassword As String)
    
    Dim strTemp As String
    Dim objWMIService As Object
    Dim objComputer As Object
    Dim colComputer As Object
    
    'Prepare to get remote information, then get it.
    On Error Resume Next
    
    If "|.|" & CreateObject("wscript.network").ComputerName & "|" Like "*|" & strComputer & "|*" Then
        Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Else
        Set objWMIService = CreateObject("WbemScripting.SWbemLocator").ConnectServer(strComputer, "root\cimv2", strUser, strPassword)
        objWMIService.Security_.ImpersonationLevel = 3
        objWMIService.Security_.AuthenticationLevel = 6
    End If
    
    If Err <> 0 Then _
        strTemp = Err.Description & " (" & Err.Number & ")"
        
    Err.Clear
    
    On Error GoTo 0
    
    'Get the remote info if appropriate.
    If Not objWMIService Is Nothing Then
        
        'Get the computer as a collection.
        Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
    
        'Set the remote user name
        For Each objComputer In colComputer
            strTemp = strTemp & "|" & objComputer.UserName
        Next
        
        'Massage the value.
        If Left(strTemp, Len("|")) = "|" Then strTemp = Mid(strTemp, Len("|") + 1)
        
    End If
    
    GetUserName = strTemp

End Function

Open in new window


I could not test it completely since I am current the only PC on the network I am using, but I am pretty sure it will do the trick.

Example:
? GetUserName()
sp01\brent
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
I will check it out Monday on our network ...
thx,mx
0
 

Author Comment

by:Concentus
Comment Utility
Thanks again for looking at this.
I believe the WMI Service object works on most networks but it's returning a "Permission Denied" on our network. That seems to be the core of my problem.
I haven't figured it out yet but, hopefully, I can query the ActiveDirectory for this information - return the username base on the computer name.
I'm going to post this as another question: "Query ActiveDirect for username from computer name".
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
@Brent ...
OK .. so, this is what happens.
At work, I have two different Computer Names (aka DeviceIDs) registered to me. So, I have two physical computers in my office ... Win7 x64 and WinXP x32.

Depending on which device I try this on, I get two different results.

My Win7 x64 device:
If I pass either one of my two registered deviceIDs, eg

?GetUserNameFromDeviceID(strComputer:="D163638")
then it does return my UserName. Good.

However, if I pass any other DeviceID - one of a person who I know is currently contained in one of several LDBs on our share drive - meaning that person is in one of my databases, I get the error shown below. (Note I had to rem out the  On Error Resume Next stmt to see the actual error).

My WinXP x32 device:
Only if I pass the DeviceID (ComputerName) that belongs to this machine do I get the my username back. Any other deviceID I pass results in the error below.

So ... Permission Denied!

This is very odd, since ... on the XP device, I have Local Admin Rights. However, IT has locked down a Win7 devices (currently being deployed across the enterprise) and we no longer have Local Admin Rights.  Now, I'm just noting this - I doubt this has anything to do with LARs, especially since on the Win7 device I can pass either of my device IDs!

error
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
So ... seems we are kind of stuck ...  in getting the User Name ...?

mx
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Transparency shows that a company is the kind of business that it wants people to think it is.
Quality of Service (QoS) options are nearly endless when it comes to networks today. This article is merely one example of how it can be handled in a hub-n-spoke design using a 3-tier configuration.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now