when you press ctrl + alt + del, the taskmanager pops up and displays all the running apps nad Iwant to make a prog that detects if app.exe is running and if its running to close it.
Printable View
when you press ctrl + alt + del, the taskmanager pops up and displays all the running apps nad Iwant to make a prog that detects if app.exe is running and if its running to close it.
Its not the exact code - but it does enumerate through all current applications running on your system. I use this to identify what the application that was in use immediately before my program.
This routine is called using:VB Code:
Private Declare Function IsWindowVisible Lib "user32" _ (ByVal hWnd As Long) As Long Public Declare Function EnumWindows Lib "user32" _ (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Public Declare Function GetWindowText Lib "user32" _ (ByVal hWnd As Long, ByVal lpString As String, _ ByVal cch As Long) As Long Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long Public Declare Function GetWindowLong Lib "user32" _ (ByVal hWnd As Long, ByVal nIndex As Long) As Long Declare Function GetActiveWindow Lib "user32" () As Long Public thisHwnd As Long Public FirstApp As Long Public FirstAppTitle As String Public Const GWL_STYLE = -16 Public Const WS_CAPTION = &HC00000 Public Const MAX_LEN = 260 Public Function _ EnumWinProc(ByVal hWnd As Long, ByVal lParam As Long) As Long Dim lRet, lWindowStyle, lWindowParent As Long Dim strBuffer As String ' Only keep windows that are visible, ' don't have parents, have a title bar and a caption, ' and are not this application, and are the first application found If hWnd <> thisHwnd Then ' Not this app If IsWindowVisible(hWnd) Then ' Window visible lWindowParent = GetParent(hWnd) If lWindowParent = 0 Then ' No parents lWindowStyle = GetWindowLong(hWnd, GWL_STYLE) If (lWindowStyle And WS_CAPTION) Then ' Has a caption strBuffer = Space(MAX_LEN) lRet = GetWindowText(hWnd, strBuffer, _ Len(strBuffer)) If lRet Then ' Has a title If FirstApp = 0 Then FirstApp = hWnd FirstAppTitle = strBuffer End If End If End If End If End If End If EnumWinProc = 1 End Function
VB Code:
thisHwnd = GetActiveWindow() FirstApp = 0 Call EnumWindows(AddressOf EnumWinProc, 0) MsgBox "The last application we were using was " & FirstApp & _ ", and has a Title of " & FirstAppTitle