| 1. | Create a new module containing the following declarations and
functions:
NOTE: In the following sample code, an underscore (_) is used as a line-
continuation character. Remove the underscore from the end of the line
when re-creating this code in Access Basic.
NOTE: You may have some Microsoft Windows API functions defined in an
existing Microsoft Access library; therefore, your declarations may be
duplicates. If you receive a duplicate procedure name error message,
remove or comment out the declarations statement in your code.
NOTE: Make sure to choose the Compile All command from the Run menu to
verify that you do not receive any compilation errors.
Option Explicit
Declare Function NetWkstaGetInfo% Lib "NetAPI.DLL" (ByVal lServer&, _
ByVal sLevel%, ByVal pbBuffer&, ByVal cbBuffer%, pcbTotalAvail%)
Declare Function GlobalAlloc% Lib "Kernel" (ByVal fFlags%, _
ByVal nSize&)
Declare Function GlobalLock& Lib "Kernel" (ByVal hMem%)
Declare Function GlobalUnlock% Lib "Kernel" (ByVal hMem%)
Declare Function GlobalFree% Lib "Kernel" (ByVal hMem%)
Declare Sub lstrcpy Lib "Kernel" (ByVal dest As Any, _
ByVal src As Any)
Declare Sub hmemcpy Lib "Kernel" (ByVal dest As Any, _
ByVal src As Any, ByVal size As Long)
Function GetBinInt (sobj As String, off As Integer)
If (Asc(Mid$(sobj, off + 1, 1)) < 128) Then
GetBinInt = Asc(Mid$(sobj, off, 1)) +_
Asc(Mid$(sobj, off + 1, 1)) * 256
Else
GetBinInt = ((&HFF - Asc(Mid$(sobj, off + 1, 1))) * 256) - _
Asc(Mid$(sobj, off, 1))
End If
End Function
Function GetWorkstationInfo (sComputer As String, _
sUserName As String, sWorkgroup As String, sLogonDomain As String)
Dim nRetSize As Integer, nStruct, ret As Integer, dummy As Integer
Dim hMem As Integer, lpMem As Long, sTemp As String
' Get the size of the return structure.
ret = NetWkstaGetInfo(0&, 10, 0&, 0, nRetSize)
If (ret <> 0) And (ret <> 2123) Then
GetWorkstationInfo = False
Exit Function
End If
' Allocate memory for the structure.
hMem = GlobalAlloc(0, CLng(nRetSize))
nStruct = nRetSize
If (hMem <> 0) Then
lpMem = GlobalLock(hMem)
' Read workstation information into structure.
ret = NetWkstaGetInfo(0&, 10, lpMem, nRetSize, nRetSize)
If (ret = 0) Then
sTemp = Space(100)
hmemcpy sTemp, lpMem, nStruct
' Retrieve the computer name.
sComputer = Space(100)
lpMem = CLng(GetBinInt(sTemp, 1)) +_
(CLng(GetBinInt(sTemp, 3)) * CLng(&H10000))
lstrcpy sComputer, lpMem
sComputer = Mid(sComputer, 1, InStr(sComputer, Chr(0)) - 1)
' Retrieve the user name.
sUserName = Space(100)
lpMem = CLng(GetBinInt(sTemp, 5)) +_
(CLng(GetBinInt(sTemp, 7)) * &H10000)
lstrcpy sUserName, lpMem
sUserName = Mid(sUserName, 1, InStr(sUserName, Chr(0)) - 1)
' Retrieve the workgroup name.
sWorkgroup = Space(100)
lpMem = CLng(GetBinInt(sTemp, 9)) +_
(CLng(GetBinInt(sTemp, 11)) * &H10000)
lstrcpy sWorkgroup, lpMem
sWorkgroup = Mid(sWorkgroup, 1, InStr(sWorkgroup, _
Chr(0)) - 1)
' Retrieve the logon domain name.
sLogonDomain = Space(100)
lpMem = CLng(GetBinInt(sTemp, 15)) +_
(CLng(GetBinInt(sTemp, 17)) * &H10000)
lstrcpy sLogonDomain, lpMem
sLogonDomain = Mid(sLogonDomain, 1, InStr(sLogonDomain, _
Chr(0)) - 1)
End If
' Free the memory allocated.
dummy = GlobalUnlock(hMem)
dummy = GlobalFree(hMem)
Else
ret = -1
End If
GetWorkstationInfo = IIf(ret = 0, True, False)
End Function
|