Detecting System Events

mtyers

New member
Joined
Oct 18, 2004
Messages
1
I am writing an application to log the applications run by a user on our network, specifically Office Apps. At the moment I run the following code every 15 min but it takes ages to complete and hogs system resources:

Code:
   Sub Main()
    Dim Ignores As String = ",RDPCLIP,USER_LOG,CTFMON,EXPLORER"
    Dim Thread, Apps As String
    Dim searcher As New ManagementObjectSearcher(New SelectQuery("Win32_Process"))
    Dim share As ManagementObject
    Dim inParams, outParams As ManagementBaseObject
    For Each share In searcher.Get()
      Thread = share("Caption")
      Thread = Thread.Substring(0, Thread.Length - 4)
      Thread = Thread.ToUpper()
      If InStr(Ignores, Thread) = 0 And InStr(Apps, Thread) = 0 Then
        inParams = share.GetMethodParameters("GetOwner")
        outParams = share.InvokeMethod("GetOwner", inParams, Nothing)
        If outParams("User") = Environment.UserName() Then
          Apps &= "," & Thread
        End If
      End If
    Next share
    WriteLine(Apps)
    Write("<press ENTER to continue>")
    ReadLine()
  End Sub

Either I try to speed up the code or (BETTER) I could listen for an application to fire up and grab the data :D

Trouble is I cant find out how to do it - do I need to do something with the SystemEvents.InvokeOnEventsThread method??? If so how :confused:

Please can anyone help? :o
 
Back
Top