Solved

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

Posted on 2010-11-26
13
483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

740 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