How could I close a program throught the API. I need to find a way of closing explorer running some code and then reloading explorer, without leaving Windows (if you know what I mean).
Printable View
How could I close a program throught the API. I need to find a way of closing explorer running some code and then reloading explorer, without leaving Windows (if you know what I mean).
You can close a window using the DestroyWindow API Function.
Thanks. Will I be able to start explorer by using:
shell strWinDir + "\explorer.exe"
even if Explorer is closed? doesn't explorer have to be open to run programs using shell?
Vlatko DestroyWindow will close a window, but it will not end the process. You need to send the WM_QUINT message to do this.
Code: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
Private Const WM_QUIT = &H12
Private sub Command1_Click()
PostMessage hwnd_of_window, WM_QUIT, 0, 0
End Sub
Thanx but, how do I get the handle for a program?
Code:Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim hWnd As Long
hWnd = FindWindow("NotePad", vbNullString) 'Here, you can supply the class name or the window caption
End Sub
And to get the Classname for a window, you'd use a Spy tool such as Spy++.