Solved

Get App Name?

Posted on 2003-11-05
9
302 Views
Last Modified: 2010-05-03
how can I get the name of the window/application oppened?
For example if user oppened WINDOWS EXPLORER. then the application will msgbox
WINDOWS EXPLORER OPENED
or whatever...
how can it be done?

thanks for any help
0
Comment
Question by:deathman5
[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
9 Comments
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9688628
you could monitor all the windows and when a new one is made you could grab the name from that.  but then your using timers.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 62 total points
ID: 9688636
"System Wide Shell Hook Dll (Version 2.0)"
http://www.freevbcode.com/ShowCode.Asp?ID=1308
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9688713
i swear ive seen that name somewhere, azrasound....  are you around in DC any?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 28

Expert Comment

by:AzraSound
ID: 9688771
No, I live in Houston.  Perhaps from another forum?  Perhaps you listen to house music?
0
 
LVL 16

Assisted Solution

by:Richie_Simonetti
Richie_Simonetti earned 32 total points
ID: 9688800
Logging use of executables in Windows

This handy little tip can be used to log the use of .exe, .lnk, .pif, .bat, and .com files on your computer. All it needs is a little registry tinkering. Place this code in a module, and set the project startup object to 'Sub Main'

Procedure

Sub Main()
If Command$ <> "" Then
Open "c:\apps\exelog.txt" For Append As #1
Print #1, Command$ & " " & CStr(Now)
Close #1
Call Shell(Command$, vbNormalFocus)
End If
End
End Sub

Registry Changes

The registry changes are:

HKEY_CLASSES_ROOT\exefile\shell\open\command to: "C:\exewrap.exe" "%1" %*
HKEY_CLASSES_ROOT\lnkfile\shell\open\command to: "C:\exewrap.exe" "%1" %*
HKEY_CLASSES_ROOT\piffile\shell\open\command to: "C:\exewrap.exe" "%1" %*
HKEY_CLASSES_ROOT\batfile\shell\open\command to: "C:\exewrap.exe" "%1" %*
HKEY_CLASSES_ROOT\comfile\shell\open\command to: "C:\exewrap.exe" "%1" %*

What happens it that instead of running the program directly, Windows calls our program, which logs filename and time, and then calls the program.
 
This code belongs to Allapi.net - Url is no longer available
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9688831
hehe, i live in ohio, by DC i meant direct connect.  this is going to bug me forever now.

But on to the question,
Are you trying to halt execution of certain programs or did you want to just log what programs are being used?  
0
 

Assisted Solution

by:toddpasley
toddpasley earned 31 total points
ID: 9691332
Hi,

I assume you mean a applicaiton you have just executed??? If so, then you have the HWnd

From the Hwnd, you can use GetWindowText WIN API to access the title.

Like....
' Add the following declarations to get window title.
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long


' then use the following code to get the title.
    Dim wincapt As String
 
    'Get the windowtext length
    wincapt = Space$(GetWindowTextLength(hwnd) + 1)
    'get the window text
    GetWindowText hwnd, wincapt, Len(wincapt)
    'remove the last Chr$(0)
    wincapt = Left$(wincapt, Len(wincapt) - 1)

    ' wincapt holds the title of the window with the handle hwnd.
    MsgBox wincapt + " just opened"




If you instead mean that you want to monitor as the user opens stuff rather than your applicaiton... then simply hook into the windows message queue and wait for WM_ACTIVATE or WM_ACTIVATEAPP messages. When one is sent, grab the hwnd and apply the code above.

Hope this helps,

Todd.
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9692020
I am not sure what are you up to:
This example will list all the windows activate at the time
http://www.thescarms.com/VBasic/alttab.asp

If you want to monitor all the windows a user open using this example, my advice is to use a timer (interval = 1000), and record the difference if new program added to the list.

However, if you already have the hwnd, then it is advisable to use the API GetWindowText & GetWindowTextLength

~ fantasy ~

0
 

Author Comment

by:deathman5
ID: 9693685
thx everybody, but Shell Hook Dll was what I wanted :)
But thx 4 anybody how helped
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

724 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