Solved

Getting Dial up Networking bytes sent and recv.

Posted on 2000-04-28
36
273 Views
Last Modified: 2010-05-02
I'm trying to get the bytes sent and recv. stats from DUN. i can't find any info on connecting a VB program into an active DUN connection and getting those(bytes sent and recv.)stats to put in
a textbox. I have everything else done
but pulling those two numbers out of the connection.
0
Comment
Question by:jmjonson
  • 14
  • 11
  • 8
  • +2
36 Comments
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
The solution I would use is to get the info off the window itself. Rather easily done using FindWindow, GetWindow and GetWindowText. If you are interested, I'll write up the code.
0
 

Expert Comment

by:LeXien
Comment Utility
you might want to look at:

GetTcpStatistics function in IPHLPAPI.DLL. Do a search on MSDN or msdn.microsoft.com for IP Helper.

thanks,
0
 

Author Comment

by:jmjonson
Comment Utility
thank for the help i have some code but only the connect speed is showing up.
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
So..., you are not interested?
0
 

Author Comment

by:jmjonson
Comment Utility
yes i'm interested, i can get the connected at 115,200 bps
and when i use the same function with the bytes sent parm all i can get is the bytes sent: no numbers which is what i'm after. the numbers after
bytes sent: ?????
bytes recived: ?????
duration: 000:00:00

this is what i want, if you can tell me
please. it's almost like i can read the
text but not the data that it can update.hmmmmmmmmm now to find out how to get the data.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
this is just a little routine that will pretty much list all the info thats in the 'Connected' window.  just add a listbox to the form:

*****Module Code*****

Declare Function EnumWindows Lib "user32" _
    (ByVal lpEnumFunc As Long, _
    ByVal lParam As Long) As Long

Declare Function EnumChildWindows Lib "user32" _
    (ByVal hWndParent As Long, _
    ByVal lpEnumFunc As Long, _
    ByVal lParam As Long) As Long

Declare Function GetWindowText Lib "user32" _
    Alias "GetWindowTextA" (ByVal hwnd As Long, _
    ByVal lpString As String, ByVal cch As Long) _
    As Long


   
Public Function EnumWinProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
    Dim RetVal As Long
    Dim WinTitleBuf As String * 255
    Dim WinTitle As String


    RetVal = GetWindowText(lhWnd, WinTitleBuf, 255)
    WinTitle = Trim$(StripNulls(WinTitleBuf))

    If Left(WinTitle, 9) = "Connected" Then
        Form1.Caption = WinTitle
        RetVal = EnumChildWindows(lhWnd, AddressOf EnumChildProc, lParam)
    End If

    EnumWinProc = True
End Function
Public Function EnumChildProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
    Dim RetVal As Long
    Dim WinTitleBuf As String * 255
    Dim WinTitle As String

    RetVal = GetWindowText(lhWnd, WinTitleBuf, 255)
    WinTitle = Trim$(StripNulls(WinTitleBuf))

    If WinTitle > " " Then
        Form1.List1.AddItem WinTitle
        Form1.List1.ItemData(Form1.List1.NewIndex) = lhWnd
    End If

    EnumChildProc = True
End Function
Public Function StripNulls(OriginalStr As String) As String
    If (InStr(OriginalStr, Chr(0)) > 0) Then
        OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
    End If
    StripNulls = OriginalStr
End Function



*****Form Code*****

Private Sub Form_Load()
    EnumWindows AddressOf EnumWinProc, 0
End Sub

0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
Yep, that's basically the code I had written...
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
Not very elegant I'm afraid...any other ideas KDivad?
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
My answer was similar except that I used GetWindow( , GW_HWNDNEXT/GW_HWNDCHILD) to run through the windows. It went a little farther in that it did find and extract the speed, upload/download bytes and duration instead of adding to a listbox. But other than that, I'm afraid I had little/nothing to offer.
0
 

Author Comment

by:jmjonson
Comment Utility
kdivad that's what i need the extracted upload and download bytes, duration data. i can list the text portions but the data isn't there, how oh how did you get the data out.please<---begging now.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
what info are you talking about?  arent the upload/download bytes the ones listed in the bytes received/bytes sent labels of the window?
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
this pretty much copies the screen in the connected box, add three labels and a timer to a form and paste this code:


****Module COde****

Declare Function EnumWindows Lib "user32" _
    (ByVal lpEnumFunc As Long, _
    ByVal lParam As Long) As Long

Declare Function EnumChildWindows Lib "user32" _
    (ByVal hWndParent As Long, _
    ByVal lpEnumFunc As Long, _
    ByVal lParam As Long) As Long

Declare Function GetWindowText Lib "user32" _
    Alias "GetWindowTextA" (ByVal hwnd As Long, _
    ByVal lpString As String, ByVal cch As Long) _
    As Long
   
Public arr(40) As String
Public Scanning As Boolean
Public i As Integer


   
Public Function EnumWinProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
    Dim RetVal As Long
    Dim WinTitleBuf As String * 255
    Dim WinTitle As String

    RetVal = GetWindowText(lhWnd, WinTitleBuf, 255)
    WinTitle = Trim$(StripNulls(WinTitleBuf))

    If Left(WinTitle, 9) = "Connected" Then
        Form1.Caption = WinTitle
        RetVal = EnumChildWindows(lhWnd, AddressOf EnumChildProc, lParam)
    End If

    EnumWinProc = True
End Function
Public Function EnumChildProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
    Dim RetVal As Long
    Dim WinTitleBuf As String * 255
    Dim WinTitle As String

    RetVal = GetWindowText(lhWnd, WinTitleBuf, 255)
    WinTitle = Trim$(StripNulls(WinTitleBuf))

    If WinTitle > " " Then
        arr(i) = WinTitle
        i = i + 1
    End If

    EnumChildProc = True
End Function
Public Function StripNulls(OriginalStr As String) As String
    If (InStr(OriginalStr, Chr(0)) > 0) Then
        OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
    End If
    StripNulls = OriginalStr
End Function



****Form Code****

Private Sub Form_Load()
    ScaleMode = 1
    Width = 4035
    Height = 2025
    Label1 = "Duration: "
    Label2 = "Bytes Received: "
    Label3 = "Bytes Sent "
    Label1.Left = 380
    Label2.Left = 380
    Label3.Left = 380
    Label1.Top = 240
    Label2.Top = 600
    Label3.Top = 960
    Timer1.Interval = 1000
    Timer1.Enabled = True
End Sub


Private Sub Scan()
    If Scanning Then Exit Sub
    Scanning = True
   
    Label1 = "Duration: "
    Label2 = "Bytes Received: "
    Label3 = "Bytes Sent: "
   
    EnumWindows AddressOf EnumWinProc, 0
   
    Label1 = Label1 & arr(3)
    Label2 = Label2 & arr(5)
    Label3 = Label3 & arr(7)
    i = 0
    Scanning = False
End Sub

Private Sub Timer1_Timer()
    If Not Scanning Then Scan
End Sub


0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
Here's the code you want:

After running, the data will be contained in ConnectSpeed, UpLoad, DownLoad and Duration. They are all strings, so you will need to convert if you need something else.

Hope this IS what you want!

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Sub Form_Load()

    Dim T_hWnd As Long
    Dim cT_hWnd As Long
    Dim WT As String
    Dim ConnectSpeed As String
    Dim UpLoad As String
    Dim DownLoad As String
    Dim Duration As String
    'Dim cT_hWnd As Long
    T_hWnd = GetWindow(GetDesktopWindow, GW_CHILD)
    Do
        WT = String$(255, 0)
        x = GetWindowText(T_hWnd, WT, 255)
        If Left$(WT, 13) = "Connected to " Then
            cT_hWnd = GetWindow(T_hWnd, GW_CHILD)
            Do
                WT = String$(255, 0)
                x = GetWindowText(cT_hWnd, WT, 255)
                If Left$(WT, 13) = "Connected at " Then
                    ConnectSpeed = Right$(WT, Len(WT) - 13)
                    ConnectSpeed = Left$(ConnectSpeed, InStr(1, ConnectSpeed, Chr$(0)) - 1)
                ElseIf Left$(WT, 9) = "Duration:" Then
                    cT_hWnd = GetWindow(cT_hWnd, GW_HWNDNEXT)
                    WT = String$(255, 0)
                    x = GetWindowText(cT_hWnd, WT, 255)
                    Duration = Left$(WT, InStr(1, WT, Chr$(0)) - 1)
                ElseIf Left$(WT, 15) = "Bytes received:" Then
                    cT_hWnd = GetWindow(cT_hWnd, GW_HWNDNEXT)
                    WT = String$(255, 0)
                    x = GetWindowText(cT_hWnd, WT, 255)
                    DownLoad = Left$(WT, InStr(1, WT, Chr$(0)) - 1)
                ElseIf Left$(WT, 11) = "Bytes sent:" Then
                    cT_hWnd = GetWindow(cT_hWnd, GW_HWNDNEXT)
                    WT = String$(255, 0)
                    x = GetWindowText(cT_hWnd, WT, 255)
                    UpLoad = Left$(WT, InStr(1, WT, Chr$(0)) - 1)
                End If
                cT_hWnd = GetWindow(cT_hWnd, GW_HWNDNEXT)
                If cT_hWnd = 0 Then Exit Do
            Loop
            Exit Do
        End If
        T_hWnd = GetWindow(T_hWnd, GW_HWNDNEXT)
        If T_hWnd = 0 Then Exit Do
    Loop

End Sub
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
Turns out that "Bytes sent:" and the data are in two different controls. This works on my system, so let me know if the data comes out mixed up (although they shouldn't...). The code assumes that the "Bytes sent:" and data labels are created in a specific order. If they mix up, it will require extra coding to check the locations of each label and adjust accordingly.
0
 

Author Comment

by:jmjonson
Comment Utility
alright i but this code in and steped thru it looking at the var. while it was running,
ElseIf Left$(WT, 9) = "Duration:" Then
                    cT_hWnd = GetWindow(cT_hWnd, GW_HWNDNEXT)
                    WT = String$(255, 0)
                    x = GetWindowText(cT_hWnd, WT, 255)
                    Duration = Left$(WT, InStr(1, WT, Chr$(0)) - 1)
wt= Duration:
then wt=blank

duration=blank

it's like it can't see the data part only the label Duration: thank both of you for the help, maybe i'm just to stupid to get this to work, at less i get the connect at 115,200 to show up but i think that's a perm. label and not a changing data var. i think it's time to buy the big set of MSDN cd's.
what else do i have $300 for.lol
thanks again you can have the points just for being so smart and helping me out.

matt
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
did you try my code? it uses a timer and shows all the info i think you need updating it every second
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
i even went through the trouble of positioning the labels and all just right so you can view it easily...paste it exactly as it is
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
jmjonson, If AzraSound's code works, go ahead and give him the points. I would like to request a favor, though. If I send you a simple project, would you be willing to run it? All it will do is create a .txt file on your desktop that has the DUN window's structure. Even if AzraSound beat me to working code (AGAIN!!!! ;-)), I would like to get my code functioning properly.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
i will look at it if youd like...and i would like to send you mine to see there are no flaws on other desktops
azrasound@aol.com
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
Forgot a small point:

jmjonson, the purpose of the project I mentioned was so that you could post the .txt file so that I could look at it. Using that file I could recreate the window and see what I need to do to "foolproof" the code.
0
 

Author Comment

by:jmjonson
Comment Utility
Adjusted points from 100 to 150
0
 

Author Comment

by:jmjonson
Comment Utility
sure i'll try, email jmjonson@mindspring.com

azra i tried your code and all i get is
the text labels, ie..bytes sent:    
but no numbers. i've pasted both in new projects, even steped through the code using debug and the strings always come back the same,
print wt
"bytes sent: "
i would love to find a anwser to this
so i'm uping the points to 150.

if you want i'll email both of you the zip files of the 4 different projects this has spawned.
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
jmjonson,

Please be patient. AzraSound and I are trying through email to figure this out. We are all getting the problem you mentioned. My code is showing the values on the first run through but not on subsequent runs if the DUN window is hidden. If it's not hidden, I can get the values constantly. His apparently has a similar problem. I missed it before because I never just let it run, I always stepped through it and checked the values on each step. We are doing our best to figure this out.

jmjonson and AzraSound,
May I make a suggestion? Since AzraSound and I are cooperating in this venture, perhaps jmjonson can get community support to halve the points on this question. This way, he(?) can post another with the rest of the points so that we can split them. Fair?

KDivad
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
as far as my code leaving blank labels, it can only mean that the order of the child windows in your DUN window is somehow different from mine...if you would please, download and run this project, it will list all running processes on your computer including child processes.  after you run it, scroll through the results it creates in the listbox until you see the referece to the DUN window...below it will be all its child windows.  please paste that information here so i can see the order that your child windows are being enumerated in.

http://www.winmag.com/columns/powertools/ptwinwatch.htm
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
I'll bet that if he tries the exact same code with the DUN window open, it'll work perfectly. That's what happened on mine.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
yes your window must be visible for my code (or KDivad's code) to work.  this is b/c both incorporate the use of the getwindowtext api.  we use this information to ensure we are gathering the information from the correct window/process.  actually, with just a few extra lines of code, if you start my program with your DUN window open, then close the DUN window, it will function.  the reason being that right now, my code checks for the windowtext to ensure it grabs the correct information.  however, after a single pass, it can store the processes handle, and use that as its reference for the remainder of the programs execution.
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
My code gets the information on the first pass regardless of whether it is open or not. I think I just figured out a "fix". The first pass can be used to store the window handles. Future passes can just retrieve the text straight from the windows. I'll have to try it out.

Later,
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
Nope, same problem as before. Seems the window doesn't bother to update when it is hidden. Probably because it wouldn't make much sense to have an ever changing caption when it can't be seen.

Another idea...
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
I'm getting closer, but the rest will have to wait until tomorrow...
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
heres what happens to my code, if this makes any sense, after the window is closed, every run through enumerating the running processes returns the values that were in the window last before it was closed.  so two hours later, i'll run my program and it will bring up the bytes and duration time that was present two hours earlier when i closed the window.
0
 

Author Comment

by:jmjonson
Comment Utility
thank you both for the help, how do i get community support to split the points between ya'll? I got a guy that programms for MS i'm going to email him and see if he can get me some inside help. if they read these 75 points to both these people for thier help.

thanks again.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
you post a question in the customer service area asking them to split the points for you and they will take care of it
0
 
LVL 5

Accepted Solution

by:
KDivad earned 75 total points
Comment Utility
<<after the window is closed, every run through enumerating the running processes returns the values that were in the window last before it was closed>>
Exact same thing happens in mine. The DUN app isn't updating the labels when it's hidden.
I experimented with displaying the window ("hidden": LockWindowUpdate and SetWindowPos(...NOREDRAW)) and grabbing the new values then undisplaying it, but it caused the window's toolbar button to flicker.)

I'd be willing to not get the points if you will post the final solution when you get it...
0
 
LVL 3

Expert Comment

by:darinw
Comment Utility
Community Support has reduced points from 150 to 75
0
 
LVL 3

Expert Comment

by:darinw
Comment Utility
Hello everyone,

I am reducing the points on this question to 75.

jmjonson: You can accept one of the Expert's comments as an answer to award the first half of the points. For the second Expert, you need to create a new question in this topic area. The title should be 'For ExpertName -- 10335956' using the appropriate Expert name and it should be for 75 points.

For your convenience, you can use this link to create the new question:
http://www.experts-exchange.com/bin/NewQForm?ta=31

darinw
Customer Service
0
 

Author Comment

by:jmjonson
Comment Utility
Thanks again, AzraSound  i'm making a new question for you
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now