Resumen Interceptar la ejecución de programas

Mensaje enviado por "Gustavo Muniz" <globo@adinet.com.uy> el 14/03/2002

No se si te sirve, pero si vos queres que cada vez que se ejecute un "exe", "com", "pif", etc., te paso esto: (supongo que despues podes cerrar la aplicacion con otra API, si no la queres dejar abierta). (te mando como hacer las dos cosas)

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:\appsexelog.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\piffileshell\open\command to: "C:\exewrap.exe" "%1" %*
HKEY_CLASSES_ROOT\batfile\shell\open\command to: "C:\exewrap.exe" "%1" %*
HKEY_CLASSES_ROOT\com\file\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.

Tip by John Percival

Esta es la segunda parte (como cerrar una aplicacion desde VB)

How can I close an application?

You can use the FindWindow and PostMessage API functions to find a window and then close it. This example show how you can close down a Window with a caption of "Calculator".

Dim winHwnd As Long
Dim RetVal As Long

winHwnd = FindWindow(vbNullString, "Calculator")
Debug.Print winHwnd
If winHwnd <> 0 Then
   RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
   If RetVal = 0 Then
      MsgBox "Error posting message."
   End If
Else
   MsgBox "The Calculator is not open."
End If

For this code to work, you must have declared the API functions in a module in your project. You must put the following in the declarations section of the module.

Declare Function FindWindow Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias _ "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com