Solved

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

Posted on 2000-05-02
4
145 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 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…

718 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