Identifying Machine or Location When a Procedure is Run

T

Tim Childs

I have a macro that I use both at work and also at home (on two machines)
but want to test for the location within the VBA code

Please can someone suggest the easiest/quickest/most elegant(?!) method for
establishing on which machine/location a procedure is being used? I realise
it is possible to get the machine ID from VBA and this requires an API.
Alternatively, I guess I could test for the existence of a particular file
or directory? Is there any other method that is better?

Many thanks in advance, Tim
 
G

GS

After serious thinking Tim Childs wrote :
I have a macro that I use both at work and also at home (on two machines) but
want to test for the location within the VBA code

Please can someone suggest the easiest/quickest/most elegant(?!) method for
establishing on which machine/location a procedure is being used? I realise
it is possible to get the machine ID from VBA and this requires an API.
Alternatively, I guess I could test for the existence of a particular file or
directory? Is there any other method that is better?

Many thanks in advance, Tim

You could use WMI...
 
P

(PeteCresswell)

Per Tim Childs:
I have a macro that I use both at work and also at home (on two machines)
but want to test for the location within the VBA code

Please can someone suggest the easiest/quickest/most elegant(?!) method for
establishing on which machine/location a procedure is being used? I realise
it is possible to get the machine ID from VBA and this requires an API.
Alternatively, I guess I could test for the existence of a particular file
or directory? Is there any other method that is better?

Would the computer's name be enough?

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

Public Function ComputerNameGet() As String
debugStackPush mModuleName & ": ComputerNameGet"
On Error GoTo ComputerNameGet_err

' PURPOSE: To extract the name of the user's PC from via Windows
API instead of environment variables
' RETURNS: Name of user's PC or a blank string

Dim L As Long
Dim lpBuffer As String * 255
Dim myComputerName As String

L = GetComputerName(lpBuffer, 255)
myComputerName = stripNulls(lpBuffer)

ComputerNameGet = myComputerName

ComputerNameGet_xit:
DebugStackPop
On Error Resume Next
Exit Function

ComputerNameGet_err:
BugAlert True, ""
Resume ComputerNameGet_xit
End Function
==================================================================
 
W

Walter Briscoe

In message <[email protected]> of Wed, 8 Feb
2012 16:56:43 in microsoft.public.excel.programming, "(PeteCresswell)"
Per Tim Childs:

Would the computer's name be enough?

Very interesting code. I hope my questions merit an answer.
==================================================================
Private Declare Function GetComputerName Lib "kernel32" Alias
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As
Long

Public Function ComputerNameGet() As String
debugStackPush mModuleName & ": ComputerNameGet"

What is debugStackPush? Probably a procedure which notes a call for
error-reporting.
Ah! As I suspected. I find "Ignore the DebugStackPush, DebugStackPop,
and BugAlert stuff - it's just my own canned error trapping." in
http://www.issociate.de/board/post/386185/Add_record_to_table_when_"No
t_In_List%22.html which is also from PeteCresswell.
Is it published? If so, where? I know it would not be hugely hard to
produce such a thing, but I do try not to reinvent things.
On Error GoTo ComputerNameGet_err

' PURPOSE: To extract the name of the user's PC from via Windows
API instead of environment variables
' RETURNS: Name of user's PC or a blank string

Dim L As Long
Dim lpBuffer As String * 255

I had not met that "* 255".
I see in Dim help it uses String * length (for fixed-length strings).
What advantage does the declaration have over Dim lpBuffer As String?
Ah! I see. GetComputerName needs a buffer of a predefined size.
Dim myComputerName As String

L = GetComputerName(lpBuffer, 255)
myComputerName = stripNulls(lpBuffer)

What is stripNulls? Part of PeteCresswell's standard environment?
 
P

(PeteCresswell)

Per Walter Briscoe:
What is stripNulls? Part of PeteCresswell's standard environment?

Oops.... That one slipped past me or I would have included it.
==============================================================
Private Function stripNulls(ByVal theOriginalString As String) As
String
debugStackPush mModuleName & ": stripNulls"
On Error GoTo stripNulls_err

If InStr(1, theOriginalString, Chr(0), vbTextCompare) Then
theOriginalString = Mid(theOriginalString, 1,
InStr(theOriginalString, Chr(0)) - 1)
End If

stripNulls = theOriginalString

stripNulls_xit:
DebugStackPop
On Error Resume Next
Exit Function

stripNulls_err:
BugAlert True, ""
Resume stripNulls_xit
End Function
==============================================================

The Debug thing is neither concise nor pretty - but I've been
using it for a lot of years and it's worked well enough that I
have not changed it in years except to clone off a "Light"
version for use in code demos.

It depends in part on MS Access being started up with a .INI file
that specifies a path to where the error reports are to be
stored, thus making it possible for many users to have their
error reports logged to the same file in the same LAN directory.

Posting it here would make a mess - bco line wrapping - and
probably elicit unkind words from anybody with dialup.

I uploaded it to 4Share.com, but can't figure out how somebody
would download it. My freebie account there is
"(e-mail address removed)" if anybody can figure out the rest.

I'd be glad to email it to you
 
T

Tim Childs

hi

thanks for those replies. I will try the simplest one first :)

best wishes

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top