Solved

Using api calls to get user name and computer name sometimes doesn't work

Posted on 2010-11-26
13
481 Views
Last Modified: 2012-05-10
Hi all,

Hope you can help.

I've install functionality in one of my clients systems to let me know who is logged in on what computer name. I'm using the functions you see below to get these values.

The problem is on some computers it works and on others it doesn't and I don't know why?

Does anyone have any ideas where I could look to resolve this issue?

Thanks:

Code:

Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSMachineName() As String

'Returns the computername
    Dim lngLen As Long, lngX As Long
    Dim strCompName As String
    lngLen = 16
    strCompName = String$(lngLen, 0)
    lngX = apiGetComputerName(strCompName, lngLen)
    If lngX <> 0 Then
        fOSMachineName = Left$(strCompName, lngLen)
    Else
        fOSMachineName = ""
    End If
End Function

'User Name function


Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If lngX <> 0 Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = ""
    End If
End Function


0
Comment
Question by:eantar
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 75
ID: 34219825
In the case where it doesn't work, what exactly happens or does not happen?

These are ... the standard API calls for doing this, and I have used them for a long time across multiple different versions of Windows and Access.

mx
0
 
LVL 5

Author Comment

by:eantar
ID: 34219896
Thanks for your reply. These are satellite clients to this one database. I'm not sure why it doesn't work for them. I just know that the db I use to track who is currently in the app isn't logging certain users.

I'll try and get more info for you.

E
0
 
LVL 75
ID: 34219910
ok
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 75
ID: 34219912
Especially if Win 7 X64 bit system ... etc.

mx
0
 
LVL 5

Author Comment

by:eantar
ID: 34219915
I'm win 7 64 bit and it works with me so I don't think that's the issue. will let you know.

Thanks again,
E
0
 
LVL 75
ID: 34219922
Yeah, same for one of my laptops ... no issue.

mx
0
 
LVL 84
ID: 34221822
Is this a standard networked application? Or are they working in a virutal machine, or a remote technology (like Terminal Services or Citrix)?
0
 
LVL 5

Author Comment

by:eantar
ID: 34221994
Good question. the front and back end sit on a server and, as far as I know, everyone accesses the application through Remote Desktop, including myself AND the users that get logged.

Any thoughts?

E
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 34225233
Check this post, especially the comment from Ian Williams:

http://www.eggheadcafe.com/software/aspnet/32622964/computer-name-of-remote-desktop.aspx



0
 
LVL 4

Expert Comment

by:BrainB
ID: 34225285
FWIW I have had some strange issues which are related to security settings (Win7 64bit). I know this because others have been solved by spending ages tweaking the settings. Everything worked on first installation on the new PC and then deteriorated as Windows updates were installed.

eg. in my home setup I have a shared drive from which I am unable to run an .exe file from the host, but can do so from another computer that accesses the drive over my newtwork(Windows XP 32bit). If I transfer the file to another unshared drive on the same PC I can run it.
0
 
LVL 5

Author Comment

by:eantar
ID: 34244032
Hey LMSConsulting. Just copied and pasted the code in the link you sent me. I'm not on Terminal Services but it looks good. I'll test it through Remote Desktop tomorrow and let you know how it goes.

Thanks,
E
0
 
LVL 5

Author Closing Comment

by:eantar
ID: 34927759
Sorry for the lateness on this. Function works really well. Thanks again.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

813 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

10 Experts available now in Live!

Get 1:1 Help Now