Results 1 to 7 of 7

Thread: keep a program from opening

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    how I make it so that no programs can be opened on the computer? like cancel the function to open the computer?
    NXSupport - Your one-stop source for computer help

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    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

  3. #3
    Guest
    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

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks, how do I make it so that it doesn't close my program?
    NXSupport - Your one-stop source for computer help

  5. #5
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Read up on the Form_QueryUnload event

  6. #6
    Guest
    Just put Cancel = True in the Form_QueryUnload event and your program will not be able to close.

  7. #7
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Originally posted by Megatron
    Just use FindWindowEx to find the window and if its open, then close it.
    The only problem with this solution is you need to know the Apps names and class that are running in order to do that.

    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"?
    Donald Sy - VB (ab)user

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