Solved

Network detection using VB6

Posted on 2007-04-06
5
443 Views
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.
Thanks,
John
0
Comment
Question by:AmericaFan
[X]
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
5 Comments
 
LVL 4

Accepted Solution

by:
quiklearner earned 250 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..
0
 
LVL 18

Assisted Solution

by:p912s
p912s earned 250 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
0
 

Author Comment

by:AmericaFan
ID: 18869177
p912s...it 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,
John
0
 
LVL 18

Expert Comment

by:p912s
ID: 18869207
You're welcome.

Thanks for the points and grade.
0
 
LVL 4

Expert Comment

by:quiklearner
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 127.0.0.1 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)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 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