how I make it so that no programs can be opened on the computer? like cancel the function to open the computer?
Printable View
how I make it so that no programs can be opened on the computer? like cancel the function to open the computer?
Get the list of active processes and kill them off one by one
It would be much easier to simply shut down the computer instead
Just use FindWindowEx to find the window and if its open, then close it.
Add the following code to a Form with a Timer.
Code:Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const WM_CLOSE = &H10
Private Sub Timer1_Timer()
Dim hApp As Long
hApp = FindWindowEx(0, 0, "My App Class", "My App Title")
If hApp <> 0 Then
SendMessage hApp, WM_CLOSE, 0, 0
DestroyWindow hApp
End If
End Sub
thanks, how do I make it so that it doesn't close my program?
Read up on the Form_QueryUnload event
Just put Cancel = True in the Form_QueryUnload event and your program will not be able to close.
The only problem with this solution is you need to know the Apps names and class that are running in order to do that.Quote:
Originally posted by Megatron
Just use FindWindowEx to find the window and if its open, then close it.
If you don't know what programs are open at run time you're kind of stuck. I've used GetForegroundWindow() with some success
and shut them down one by one but eventually you get to desktop and it shut down windows. Anyone know what the desktop
reference is? e.g. the tray window can be referenced by:
trayWhnd = FindWindow("Shell_traywnd", vbNullString)
Might that be "Shell_desktopwnd"?