Solved

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

Posted on 2010-11-26
13
482 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

821 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