Solved

A few questions in one! All about modems and the sys tray.

Posted on 2000-05-02
4
144 Views
Last Modified: 2012-05-04
OK. Firstly, I need to know how to detect when my modem both connects and disconnects from my ISP. I need to be able to time the interval between.

Secondly, I'd like to know how to minimize my program to the system tray (the one on the bottom right by the clock, if I've got the name wrong!).

Thanks in advance.
0
Comment
Question by:stesherlock
[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
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2771589
0
 
LVL 15

Accepted Solution

by:
cquinn earned 60 total points
ID: 2772518
The following is the code of an application I have to log all modem connections.  I have it in startup and it logs all connections into a separate log file for each day, named in the format YYYYMMDD.LOG, in the same directory as the application.  I use it to calculate connection times for myself, my wife and my daughter (it writes the logon name to the log) so I have ammunition when the phone bill comes in!  It runs in background and does not appear in the taskbar or task manager list, so they don't know how I know!

Put a timer on a form with a reasonable interval set eg every second or minute.

Add the following code to the form:

Option Explicit

Private Sub Form_Load()
Dim OwnerhWnd As Long
Dim ret As Long

' Make sure the form is invisible:
Me.Visible = False

' Set interval for timer for 5 seconds, and make sure it is enabled:
tmrTimer1.Interval = 10000
tmrTimer1.Enabled = True

' Grab the background or owner window:
OwnerhWnd = GetWindow(Me.hwnd, GW_OWNER)
' Hide from task list:
ret = ShowWindow(OwnerhWnd, SW_HIDE)

ModemLogFile = sFixDir(App.Path) & Format$(Date, "yyyymmdd") & ".log"
sUsername = GetUser()
WriteToLog "Application opened"
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   WriteToLog "Application closed"
End Sub

Private Sub tmrTimer1_Timer()
Static lConnected As Long, lConnection As Long
DoEvents
lConnection = IsNetConnected()
If Not lConnected And lConnection Then
    WriteToLog "Connection opened"
ElseIf lConnected And Not lConnection Then
   WriteToLog "Connection closed"
Else
    Exit Sub
End If
lConnected = lConnection

End Sub


*********************************
create a module and add the following code:
**********************************

Option Explicit
'Retrieve a network login ID
Public Declare Function WNetGetUser Lib "mpr" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpusername As String, lpnLength As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Public Declare Function InternetGetConnectedState _
   Lib "wininet.dll" (ByRef lpdwFlags As Long, _
   ByVal dwReserved As Long) As Long

Public ModemLogFile As String
Public sUsername As String

Public Const SW_HIDE = 0
Public Const GW_OWNER = 4

Public Function IsNetConnected() As Boolean

  'if there is a connection
   IsNetConnected = InternetGetConnectedState(0&, 0&)
     
End Function

Public Sub WriteToLog(sAction As String)
Dim iFileNum As Integer
iFileNum = FreeFile()
Open ModemLogFile For Append As iFileNum
Write #iFileNum, sAction; Format$(Now, "hh:nn:ss dd mmm yyyy"); sUsername
Close iFileNum
End Sub

Function GetUser() As String
Dim ReturnCode As Integer
Dim UserName As String
Dim lp As String
    Dim size As Long
    GetUser = "Nonetwrk"
    UserName = String$(255, 0)
    size = Len(UserName)
    ReturnCode = WNetGetUser&(lp, UserName, size)
    If ReturnCode = 0 Then
        While Asc(Mid$(UserName, size, 1)) = 0
            size = size - 1
        Wend
        GetUser = Left$(UserName, size)
    End If
End Function

Public Function sFixDir(sIncoming As String) As String
If Right$(sIncoming, 1) = "\" Then
    sFixDir = sIncoming
Else
    sFixDir = sIncoming & "\"
End If
   
End Function

Public Sub Main()
Call ShowWindow(frmModemLog.hwnd, SW_HIDE)

End Sub



0
 

Author Comment

by:stesherlock
ID: 2775765
I like your prog cquinn, but do you know if I can add the ISP that is connected to the log file?

I ask this because I am signed up with about 5 ISPs, and one or two of them are freephone numbers, so I'd like to be able to know whether or not it adds to the phone bill!
0
 

Author Comment

by:stesherlock
ID: 2950120
Comment accepted as answer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

737 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