Solved

Network detection using VB6

Posted on 2007-04-06
5
439 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now