Results 1 to 6 of 6

Thread: Closing Widows, Closing an app

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    1

    Closing Widows, Closing an app

    How does one detect if a certian application is opened, and how do you close it from VB?

    I have an ExitWindowsEx procedure that shuts the computer down at a certian time (closing time ). When the computer is rebooted, the "Windows was shut down improperly" comes up, and scandisk runs. How do I "shut down properly" to prevent this?

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    u can use findwindow to detect if an application is open, then SendMessage with wm_close as the message to close it

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    3.  
    4. Private Const WM_CLOSE = &H10
    5.  
    6. Private Sub Command1_Click()
    7. Dim WinWnd As Long
    8.     WinWnd = FindWindow(vbNullString, "Caption Of Open Application")
    9.     If WinWnd > 0 Then  'it is running, so close it
    10.         PostMessage WinWnd, WM_CLOSE, CLng(0), CLng(0)
    11.     End If
    12. End Sub

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yeah, that's the one

  5. #5
    Fanatic Member
    Join Date
    Aug 2001
    Location
    Connecticut
    Posts
    855
    I'm interested in this too. But does this work for app/windows that normally throw up modal dialogs like "Do you want to save..." before closing?
    VB 6.0, Access, Sql server, Asp

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yes, but that is a child window, you need to use FindWindowEx to get the handle of it...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width