PDA

Click to See Complete Forum and Search --> : net send...


Owen Holiday
Mar 11th, 2001, 11:08 AM
Does anyonw know if there is any way to create a program that can detect when the "net send" function is used on the WinNT network, so that when the program is running, it can detect if there is a message is sent to that machine.

Any suggestions at all would be greatly appreciated...

Owen.

Mark Sreeves
Mar 12th, 2001, 05:51 AM
Right then.
The pop-up window has the title "Messenger Service" so you need to get titles of all the running apps and then loop through them to find it

I've just put a Msgbox here when it is found.


paste this into a module and call it from a timer control or a timer() loop



Option Explicit
'/////////////////////////stuff for checking other windows///////////////////////////////////////
Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal LParam As Long) As Long
Private handles() As Long

Public Counter As Long


Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal LParam As Long) As Long
Dim sCaption As String * 255
ReDim Preserve handles(Counter)
handles(Counter) = hwnd
Counter = Counter + 1
EnumWindowsProc = hwnd
End Function
Public Sub GetWindows()
Dim textlen As Long ' receives length of text of the window
Dim wintext As String ' receives the text of the window
Dim slength As Long ' receives the length of the returned string
Dim n As Long
Dim i As Integer

ReDim handles(0)
Counter = 0
Call EnumWindows(AddressOf EnumWindowsProc, 0&)


For n = 0 To UBound(handles())
' Find out how many characters are in the window's text.
' Add 1 to compensate for the terminating null.
textlen = GetWindowTextLength(handles(n)) + 1
' Make sufficient room in the buffer.
wintext = Space(textlen)
' Retrieve the text of window Form1.
slength = GetWindowText(handles(n), wintext, textlen)


'Debug.Print wintext
' Remove the empty space from the string, if any.
wintext = Left(wintext, slength)
If wintext <> "" Then
Debug.Print wintext
End If
' Display the result.
If Trim(wintext) = "Messenger Service" Then
'
MsgBox "message recieved"
End If
Next n
End Sub

'////////////////////////////////////////////////////////////////