Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote PC Monitoring 1

Status
Not open for further replies.

MisterC

IS-IT--Management
Apr 19, 2001
501
US
I need code to monitor a lab's computers - something that will show the currently running applications and other relevent information for each pc. The ability to capture a screenshot would be nice too, though PCAnywhere / VNC type remote-control ability is not a necessity...

Any help?
Thanks!
 
A very broad question! I would suggest looking at a site such as and having a look through the various API's available for such a question. Anyway, to get you started here is a solution to show the running windows and their captions: (Place a command button on your form and name it command1)
Code:
Option Explicit

Private Declare Function apiGetClassName Lib "user32" Alias _
                "GetClassNameA" (ByVal Hwnd As Long, _
                ByVal lpClassname As String, _
                ByVal nMaxCount As Long) As Long
Private Declare Function apiGetDesktopWindow Lib "user32" Alias _
                "GetDesktopWindow" () As Long
Private Declare Function apiGetWindow Lib "user32" Alias _
                "GetWindow" (ByVal Hwnd As Long, _
                ByVal wCmd As Long) As Long
Private Declare Function apiGetWindowLong Lib "user32" Alias _
                "GetWindowLongA" (ByVal Hwnd As Long, ByVal _
                nIndex As Long) As Long
Private Declare Function apiGetWindowText Lib "user32" Alias _
                "GetWindowTextA" (ByVal Hwnd As Long, ByVal _
                lpString As String, ByVal aint As Long) As Long
Private Const mcGWCHILD = 5
Private Const mcGWHWNDNEXT = 2
Private Const mcGWLSTYLE = (-16)
Private Const mcWSVISIBLE = &H10000000
Private Const mconMAXLEN = 255

Function ShowProcesses()
Dim lngx As Long, lngLen As Long
Dim lngStyle As Long, strCaption As String
Dim strSQLUpdate As String

On Error Resume Next

    lngx = apiGetDesktopWindow()
    lngx = apiGetWindow(lngx, mcGWCHILD)

    Do While Not lngx = 0
        strCaption = fGetCaption(lngx)
        If Len(strCaption) > 0 Then
            lngStyle = apiGetWindowLong(lngx, mcGWLSTYLE)
            If lngStyle And mcWSVISIBLE Then
                Debug.Print "Class Name: " & fGetClassName(lngx) & vbCrLf & "Class Info: " & fGetCaption(lngx) & vbCrLf
            End If
        End If
        lngx = apiGetWindow(lngx, mcGWHWNDNEXT)
    Loop
End Function

Private Function fGetClassName(Hwnd As Long) As String
    Dim strBuffer As String
    Dim intCount As Integer
   
    strBuffer = String$(mconMAXLEN - 1, 0)
    intCount = apiGetClassName(Hwnd, strBuffer, mconMAXLEN)
    If intCount > 0 Then
        fGetClassName = Left$(strBuffer, intCount)
    End If
End Function

Private Function fGetCaption(Hwnd As Long) As String
    Dim strBuffer As String
    Dim intCount As Integer

    strBuffer = String$(mconMAXLEN - 1, 0)
    intCount = apiGetWindowText(Hwnd, strBuffer, mconMAXLEN)
    If intCount > 0 Then
        fGetCaption = Left$(strBuffer, intCount)
    End If
End Function

Private Sub Command1_Click()
ShowProcesses
End Sub



----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Thanks for your reply,
Maybe I can narrow down my "broad" question:
This is for a lab - I want to remotely monitor what the students are doing on the computers in the lab. That is, an application on my computer that lists info like:

Code:
REMOTE PC                  USER            ACTIVE APP
Code:
Lab151 (123.1.1.7)        Student1          SOL.EXE
Lab152 (123.1.1.11)       Student14         WORD.EXE
Lab153 (123.1.1.3)        Student3          WORD.EXE

And it would be great if I could pull up a screenshot of that computer running "SOL.EXE".....
Thanks!
etc...
 
OK - I've done something very similar recently. The option I used was to use a server executable, a client executable and a database.

Basically the database contains two tables. One to hold the parameters of what you want to find (e.g. Username, Current Applications etc...). The other table contains the details of what you have requested (e.g. the username, current windows etc.)

What my server program did was update the database with whatever I wanted to view (e.g. it would set the Username parameter in the first table to 'True'). The client executable was on a timer every 30 seconds and looked at the parameters. When a 'True' parameter was found it would gather the data, insert in into the second table and set the paramter back to 'False'. These results could then be viewed from the server executable (i.e. your machine).

What you need to do, if you decide to do it like this, is create a client executable that would run on each lab machine and it would contain all the necessary function (like the one I provided in the previous answer) and this would then return its output to the database.

The "screenshot" would work in a similar way (although you could only view what the user was looking at - you couldn't get a screenshot of a minimised window - someone correct me if i'm wrong!). Try looking at the GetDC and StretchBlt API's.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
That sounds like a good approach, though I'd love to do it *without* a client exe.... (Oh, well wishful thinking I guess.)
Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top