Solved

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

Posted on 2010-11-26
13
484 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 85
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 85

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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 …

726 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