• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Listening to the user running applications

Hi all
I have a small project installed in each workstations that saved the user name ,date and time of login to the Network to a database.
I need to add another task to this project that's all the applications that the user runs them during his session with the time.
For example :
Suppose the user click on the (Microsoft word) then the system will add the following :
Application name, and the time to the database.

Is it possible to do so please advice or give me any other idea to perform this task.

Zr
0
zrikat
Asked:
zrikat
  • 8
  • 7
  • 3
1 Solution
 
AzraSoundCommented:
http://codeguru.developer.com/vb/articles/1968.shtml

this will display all running programs
0
 
AzraSoundCommented:
sorry not what youre looking for is it, you will probably need to use subclassing
0
 
zrikatAuthor Commented:
Edited text of question.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
zrikatAuthor Commented:
Thank you Azr
but this only display the active pplications which I can display them.
what I want exactly is to Listen to the user when he run an application automaticly add it to the DB.


0
 
zrikatAuthor Commented:
Thank you Azr
but this only display the active pplications which I can display them.
what I want exactly is to Listen to the user when he run an application automaticly add it to the DB.


0
 
MaximkaCommented:
Read MSDN about Hooks . You can via Hook to catch message that user sends by his clicking on each object and at this moment to check if List of tasks was udated by new task .Then You will know that the task was added or removed and You can to update Your database with the Time when it happened.
It is not most simple way , but it will work 100 %.
Hope this will help You.
0
 
AzraSoundCommented:
i said subclassing earlier, i meant hooks
0
 
zrikatAuthor Commented:
Is there any example or code that I can follow it to understand who the Hook work???
0
 
AzraSoundCommented:
http://blackbeltvb.com/

theres an example on hooking there called MHHook but you can only download it if youre a subscriber, whatever that means
0
 
AzraSoundCommented:
0
 
MaximkaCommented:
Sorry, AzraSound I didn't mean to argue You , I just described him what exactly the Key word that will help him for searching in MSDN. That's all.
Sorry.
0
 
zrikatAuthor Commented:
Is there any other way ?
the Hook is very difficult to understand?



0
 
MaximkaCommented:
Yes, You can work with timer and GetMessage , but it will catch performance percantage of your CPU.
0
 
zrikatAuthor Commented:
Max
Let me try it ?
would you please provide me with the code or the steps.


0
 
AzraSoundCommented:
zrikat, i created a small project using a timer to continuously check for running windows and display a msgbox when a new one arises. Some considerations before trying this out, I set the timer to 5 seconds, again I dont know what kind of stall this will cause on performance nor do i know the effects on memory. You may wish to monitor these when this runs. Also, you will notice i declare the array arrWindows(20) which specifies the number of elements to hold. If you feel that more processes than this can be runing at one time, please increase it accordingly.  Another note, I use Windows 98 and VB 6.0  SP3.  I have no idea what kind of conflicts or discompatibility there might be with other platforms. Please let me know how it works and I will try to adjust it accordingly.  Now for the code, it requires a module and one form with a timer control and a listbox and a command button. Upon loading the form, all running processes are listed. After pressing the command button, al running processes will be compared to the previous instance to see if a new program was begun.

In the module:

Option Explicit


Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const MAX_PATH As Integer = 260
Public Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * MAX_PATH
End Type
Public Declare Function CreateToolhelpSnapshot Lib "Kernel32" _
    Alias "CreateToolhelp32Snapshot" _
    (ByVal lFlags As Long, ByVal lProcessID As Long) As Long

Public Declare Function ProcessFirst Lib "Kernel32" _
    Alias "Process32First" _
    (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Public Declare Function ProcessNext Lib "Kernel32" _
    Alias "Process32Next" _
    (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Public Declare Sub CloseHandle Lib "Kernel32" _
    (ByVal hPass As Long)




On the Form:

Option Explicit
Dim arrWindows(20) As Variant
Dim i As Integer

Private Sub Command1_Click()
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Dim hSnapShot As Long
    Dim uProcess As PROCESSENTRY32
    Dim r As Long
    Dim j As Integer
    List1.Clear
    hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    If hSnapShot = 0 Then
        Exit Sub
    End If
    uProcess.dwSize = Len(uProcess)
    r = ProcessFirst(hSnapShot, uProcess)
    Do While r
        For i = 0 To UBound(arrWindows)
            If uProcess.szExeFile = arrWindows(i) Then
                Exit For
            Else
                If i = UBound(arrWindows) Then _
                    MsgBox Now & vbCrLf & "Program: " & _
                        uProcess.szExeFile, vbInformation, _
                        "New Program Started"
            End If
        Next
        List1.AddItem uProcess.szExeFile
        arrWindows(j) = uProcess.szExeFile
        j = j + 1
        r = ProcessNext(hSnapShot, uProcess)
    Loop
    Do
    arrWindows(j) = ""
    j = j + 1
    Loop Until j = UBound(arrWindows)
    Call CloseHandle(hSnapShot)
End Sub


Private Sub Form_Load()
    Dim hSnapShot As Long
    Dim j As Integer
    Dim uProcess As PROCESSENTRY32
    Dim r As Long
    Timer1.Enabled = False
    hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    If hSnapShot = 0 Then
        Exit Sub
    End If
    uProcess.dwSize = Len(uProcess)
    r = ProcessFirst(hSnapShot, uProcess)
    Do While r
        List1.AddItem uProcess.szExeFile
        arrWindows(j) = uProcess.szExeFile
        j = j + 1
        r = ProcessNext(hSnapShot, uProcess)
    Loop
    Call CloseHandle(hSnapShot)
End Sub


0
 
zrikatAuthor Commented:
Dear AzraSound

I appreciate your help really you are very respected man thank you very much.

Please have a look at :
http://www1.experts-exchange.com/Computers/Programming/Windows/Visual_Basic/Q_10321906.html

Zr
0
 
zrikatAuthor Commented:
It's working excellent without any conflicts on memory or the computer it self.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 8
  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now