?
Solved

Get App Name?

Posted on 2003-11-05
9
Medium Priority
?
312 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
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 186 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 96 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 93 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

840 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