Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Network detection using VB6

Posted on 2007-04-06
Medium Priority
Last Modified: 2012-08-14
VB6 application development with XP OS running on a WAN using Active Directory.

Is it possible to create code in an application that is built using VB6 to detect if the computer running the application is connected to a network. I am synchronizing an Access DB thru my VB6 Code and want to make sure the user has there laptop connected to the network.
Question by:AmericaFan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

quiklearner earned 1000 total points
ID: 18867373
to do it programmatically, yo uCOULD use a winsock control (can be created both with or without a form) however i am not sure about a way to explicitly find out if it connected.  You could check the localip property and i would imagine it may be reset depending on if you use dhcp or not.  Another possibility that would specifically do exactly waht you asked would be to use a windows shell object to execute a command line like: ipconfig.exe /all >>c:\temp.txt
This would place the contents of running the ipconfig /all into the file named c:\temp.txt that you could then parse to see if the cable is actually "disconnected" or not.
My last recommendation which would be easiest wuold be to just error trap the db.connect method, and assume a connection problem if you get an error there (although it could be the db down or some other network problem)

Hope this helps and if you need more details on any suggestions just let me know which ones..
LVL 18

Assisted Solution

p912s earned 1000 total points
ID: 18867516
>>Access DB thru my VB6 Code and want to make sure the user has there laptop connected to the network.
Is this a mapped drive when connected to the network? You could test for the *.mdb

If Dir("M:\SomeFolder\ServerFile.mdb")<>"" Then
   'file exists do your sync...
End If

Author Comment

ID: 18869177 is a mapped drive when synchronizing so your answer should be the simplest one and I will probably use it in my code, but I wanted to split the points because I am very interested in learning quiklearner's methods. If quiklearner could provided me with a little more info on the methods other than the error trapping I would be most appreciative.
Thanks to both of you,
LVL 18

Expert Comment

ID: 18869207
You're welcome.

Thanks for the points and grade.

Expert Comment

ID: 18871606
To use the winsock control:
If you have a form, go into components and select the "Microsoft Winsock Control".  Draw one on your form.
If you don't have a form, you will need to go into references, click browse, and in your system32, find the file mswinsck.ocx.  Of course, make sure a reference shows up called "Microsoft Winsock Control" and is checked.  Then you will need to create a winsock object.
Regardless of if it is a control or an object, it will have a property called LocalIP.  This is the current LocalIP.  Play with this property with it both on and off the network to see what the difference will be.  When I did it just now, it was when the network was off and my local 192 address when it is on.

Heres a sample to demonstrate the second:
    Dim sTempFileName As String, sContents As String
    sTempFileName = "c:\temp.txt"
    CreateObject("WScript.Shell").Run "cmd /c ipconfig > " & sTempFileName, 0, True
    sContents = CreateObject("Scripting.FileSystemObject").OpenTextFile(sTempFileName, 1).ReadAll
    Kill sTempFileName
    If InStr(1, sContents, "disconnected") And Not InStr(1, sContents, "IP Address") Then
        MsgBox "Looks like it is disconnected"
    End If

First I declared all my vars and set the temp file name.
I execute the Run method of the shell object, executing a program, 0 indicating a hidden window, and True indicating I want to wait until the application has completed. What I run is the ipconfig application.  Since the ipconfig is a command-line app, I actually have to run it within a cmd shell.  The > redirects the output of the command-line application to a file.
Next I got the contents of the temp file placed into a string var to make for easy checking.  1 in the OpenTextFile method indicates ForReading.
I then remove the temp file.
Lastly I check and determine whether or not it looks disconected.  I just used criteria that worked on my system and with my protocols.  You will probably will want to verify the results of the ipconfig on your target system(s) to ensure proper function.  The way I coded it, it would work for computers that are TCP/IP and the check should work for computers with multiple nics (even if one or another wern't currently connected)

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question