Solved

Get App Name?

Posted on 2003-11-05
9
301 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA to copy paste columns form one file to other 20 100
Spell Check in VB6 13 138
VBA - If Bookmark = "XXBOOKMARKXX" then 15 51
add criteria to query in VB, Access 2003 2 33
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

730 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