?
Solved

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

Posted on 2000-05-02
4
Medium Priority
?
146 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 240 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

764 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