[AccessD] Track PC Number

Heenan, Lambert Lambert.Heenan at AIG.com
Tue Jun 12 10:16:14 CDT 2007


It's unreliable because the setting of the environment variables is
dependant of the local computer administrators' decision. In some shops they
set the variables in login scripts, in others they don't. So you can never
be certain that Environ is going to return a value. The API calls should
always work.

Here's some code...

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

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

Function fOSUserName() As String
' Returns the network login name, or if this is a secured database, the
CurrentUser

Dim lngLen As Long, lngX As Long
Dim strUserName As String
    If CurrentUser <> "Admin" Then ' If we have logged in to a secure
database
        fOSUserName = CurrentUser
    Else
        strUserName = String$(254, 0)
        lngLen = 255
        lngX = apiGetUserName(strUserName, lngLen)
        If lngX <> 0 Then
            strUserName = left$(strUserName, lngLen - 1)
            fOSUserName = strUserName
        Else
            fOSUserName = ""
        End If
    End If
End Function

'******************** Code Start **************************
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code courtesy of
'Dev Ashish
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

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Bartow
Sent: Tuesday, June 12, 2007 10:56 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Track PC Number


I'm pretty sure that there's not a Mac version of Access. I'm assuming the
help reference was for Word, Excel or PowerPoint.

This is the first I've noticed the Environ() function. Seems like it would
save a lot of coding in lieu of the half a dozen Windows API calls I use to
do what it can do. I was just wondering if it was unreliable that there are
so many people using and posting API calls to do the same thing. (I
certainly didn't write the API calls I'm using!)

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Heenan, Lambert
Sent: Tuesday, June 12, 2007 8:49 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Track PC Number

The Environ() function has been available is all versions of Access since
1.0, but that's in a Windows setting. Are you running Access on a Mac in a
Windows emulator? In which case Environ should work, but only if your
virtual windows machine actually sets an environment variable called
UserName and/or another one called ComputerName. Those variables are
typically set by login scripts. If they are not set then you have to use the
API calls to retrieve the information.

If you are running the native Mac version of Access (is there such a beast?)
then I can offer no help, not knowing any Mac APIs.

Lambert

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list