Win32 - Check if user is connected to a network

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Win32 - Check if user is connected to a network

Post by BackupUser »

Code updated For 5.20+

Restored from previous forum. Originally posted by MrVainSCL.

Here is a small codesnip to check if you are connected to a network or not... Maybe usefull for some people trying to write any network based appz.

Here is a normal version:

Code: Select all

; ------------------------------------------------------------
;
; PureBasic Win32 API - CheckNetworkConnection - Example v1.0
;
; by MrVainSCL! aka Thorsten   19/Jan/2003    PB v3.51+
;
; ------------------------------------------------------------
;
    If GetSystemMetrics_(#SM_NETWORK) And $01 = 1  
      state$ = "Connected"
    Else
      state$ = "Disconnected"
    EndIf
    ;
    MessageRequester("Are we connected to a Network?","We are "+state$,0)
End
;
; ------------------------------------------------------------
Here is a Procedure() version:

Code: Select all

; ------------------------------------------------------------
;
; PureBasic Win32 API - CheckNetworkConnection - Example v1.0
;
; by MrVainSCL! aka Thorsten   19/Jan/2003    PB v3.51+
;
; ------------------------------------------------------------
;
    Procedure MyCheckNetworkConnection()  
        If GetSystemMetrics_(#SM_NETWORK) And $01 = 1  
          result = 1
        Else
          result = 0
        EndIf
        ;
        ProcedureReturn result
    EndProcedure;
    ;
    ; -------- Check if user is connected to a network -------- 
    ;
    If MyCheckNetworkConnection() = 1
      state$ = "Connected"
    Else
      state$ = "Disconnected"
    EndIf
    ;
    MessageRequester("Are we connected to a Network?","We are "+state$,0)
End
;
; ------------------------------------------------------------

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten