Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


952


Retrieving system information
The Windows API provides a number of functions that you’ll find useful for retrieving information
about the Windows system, the hardware, and other software that may be running on the com-
puter. This information is often useful for avoiding problems like running out of disk space or try-
ing to write data to a CD-ROM drive. These functions also provide handy information, like the
location of the Windows and temporary directories.

GetCommandLineA
GetCommandLine returns the command line used to start up the current application. This may
be useful if you need to know whether the shortcut used to start an Access application included
references to a macro or VBA procedure.

Declare Function apiGetCommandLine _
Lib “kernel32” _
Alias “GetCommandLineA” () As Long

When run from the immediate window in Access VBA, the function returns the full path, including
the executable name, for Microsoft Access. The command line is returned in quotation marks.

The following function serves as a wrapper around GetCommandLineA:

Declare Sub CopyMemory _
Lib “kernel32” _
Alias “RtlMoveMemory” ( _
pDst As Any, _
pSrc As Any, _
ByVal ByteLen As Long _
)
Declare Function lstrlen _
Lib “kernel32” _
Alias “lstrlenA” ( _
ByVal lpString As Long _
) As Long
Function GetCommandLine() As String
Dim RetStr As Long
Dim SLen As Long
Dim Buffer As String

‘Get a pointer to a string containing the command line:
RetStr = apiGetCommandLine
‘Get the length of that string:
SLen = lstrlen(RetStr)
If SLen > 0 Then
‘Create a buffer:
GetCommandLine = Space$(SLen)
‘Copy to the buffer:
CopyMemory ByVal GetCommandLine, ByVal RetStr, SLen
End If
End Function
Free download pdf