Test To See If Laptop Is Connected To Network (1 Viewer)

CJBIRKIN

Drink!
Local time
Today, 05:27
Joined
May 10, 2002
Messages
256
Hi all,

Is it possible to test if a computer is connected to a network?

To make it clear i will have no prior knowledge of what is on the network. The only fact is that it will be running a windows server application.

Any help greatfully recieved.

Cheers

Chris
 

namliam

The Mailman - AWF VIP
Local time
Today, 06:27
Joined
Aug 11, 2003
Messages
11,695
Code:
'************ 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
'
Private Type WKSTA_USER_INFO_1
   wkui1_username As Long     'name of the user _
                              currently logged on _
                              to the workstation.
   wkui1_logon_domain As Long 'the domain name of _
                              the user account of the _
                              user currently logged on
   wkui1_oth_domains As Long  'list of other LAN _
                              Manager domains browsed _
                              by the workstation.
   wkui1_logon_server As Long 'name of the computer _
                              that authenticated the _
                              server
End Type

Private Declare Function apiWkStationUser Lib "Netapi32" _
  Alias "NetWkstaUserGetInfo" _
  (ByVal reserved As Long, _
  ByVal Level As Long, _
  bufptr As Long) _
  As Long
  
Private Declare Function apiStrLenFromPtr Lib "kernel32" _
  Alias "lstrlenW" _
  (ByVal lpString As Long) _
  As Long

Private Declare Sub sapiCopyMemory Lib "kernel32" _
  Alias "RtlMoveMemory" _
  (hpvDest As Any, _
  hpvSource As Any, _
  ByVal cbCopy As Long)


Public Function fUserNTDomain() As String
'*******************************************
'Name:          fUserNTDomain  [NT ONLY] (Function)
'Purpose:       Find NT Domain name of current user
'Author:        Dev Ashish
'Date:          Thursday, January 14, 1999
'Called by:     Any
'Calls:         NetWkstaUserGetInfo, RTLMoveMemory
'Inputs:        None
'Returns:       NT Domain Name of Current User
'*******************************************
On Error GoTo ErrHandler
  Dim lngRet As Long
  Dim lngPtr As Long
  Dim tNTInfo As WKSTA_USER_INFO_1
  
  lngRet = apiWkStationUser(0&, 1&, lngPtr)
  If lngRet = 0 Then
    Call sapiCopyMemory(tNTInfo, ByVal lngPtr, LenB(tNTInfo))
    If Not lngPtr = 0 Then
      With tNTInfo
        fUserNTDomain = fStringFromPtr(.wkui1_logon_domain)
      End With
    End If
  End If

ExitHere:
  Exit Function
ErrHandler:
  fUserNTDomain = vbNullString
  Resume ExitHere
End Function

Private Function fStringFromPtr(lngPtr As Long) As String
Dim lngLen As Long
Dim abytStr() As Byte
  lngLen = apiStrLenFromPtr(lngPtr) * 2
  If lngLen > 0 Then
    ReDim abytStr(0 To lngLen - 1)
    Call sapiCopyMemory(abytStr(0), ByVal lngPtr, lngLen)
    fStringFromPtr = abytStr()
  End If
End Function
'************ Code End *************
I found above code to get the current NT server some time ago.... Hope it helps...

Regards
 

CJBIRKIN

Drink!
Local time
Today, 05:27
Joined
May 10, 2002
Messages
256
Hi Namliam,

Works like a charm! :D

Cheers

Chris.
 

Users who are viewing this thread

Top Bottom