Results 1 to 3 of 3

Thread: Closing Control Panel, etc.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    15
    Can someone give me some code to close the following windows if they are open:

    Control Panel
    Printer Panel
    Internet Explorer
    Netscape Navigator
    Netscape Communicator

    I need to make a program to restrict access to certain functions, but i don't want to use registry, so i am gonna make a timer and every couple of seconds it will make a sweep and close any of the above windows if they are open.

    Pleaze help me!

    Thanxs alot!

  2. #2
    Guest
    Code:
    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    
    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 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 GetWindowText Lib "user32" _
    Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _
    lpString As String, ByVal cch As Long) As Long
    
    Private Declare Function GetWindowTextLength _
    Lib "user32" Alias "GetWindowTextLengthA" (ByVal _
    hwnd As Long) As Long
    
    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    
    Private Declare Function OpenProcess Lib "kernel32" _
    (ByVal dwDesiredAccess As Long, ByVal bInheritHandle _
    As Long, ByVal dwProcessId As Long) As Long
    
    Private Declare Function GetWindowThreadProcessId _
    Lib "user32" (ByVal hwnd As Long, lpdwProcessId As _
    Long) As Long
    
    Private Declare Function GetExitCodeProcess _
    Lib "kernel32" (ByVal hProcess As Long, lpExitCode As _
    Long) As Long
    
    Private Declare Function TerminateProcess _
    Lib "kernel32" (ByVal hProcess As Long, ByVal _
    uExitCode As Long) As Long
    
    Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    Private Const WM_CLOSE = &H10
    Private Const WM_DESTROY = &H2
    
    
    Private Sub Timer1_Timer()
    
        Dim hCPWin As Long
        Dim hPWin As Long
        Dim hIEWin As Long
        Dim lngIE As Long
        Dim strBuffer As String
        Dim lngLength As Long
        Dim intCount As Integer
        Dim lHwnd As Long
        Dim lProcess As Long
        Dim lExitCode As Long
        Dim p As Integer
    
        hCPWin = FindWindow(vbNullString, "Control Panel")
        hPWin = FindWindow(vbNullString, "Printers")
    
        If hCPWin <> 0 Then
            PostMessage hCPWin, WM_CLOSE, 0, 0
            PostMessage hCPWin, WM_DESTROY, 0, 0
        ElseIf hPWin <> 0 Then
            PostMessage hPWin, WM_CLOSE, 0, 0
            PostMessage hPWin, WM_DESTROY, 0, 0
        End If
    
    
        Do
            lngIE = FindWindowEx(0, lngIE, "IEFrame", vbNullString)
            lngLength = GetWindowTextLength(lngIE)
            strBuffer = Space(lngLength)
            Call GetWindowText(lngIE, strBuffer, Len(strBuffer))
            If Len(Trim(strBuffer)) > 0 Then
                intCount = intCount + 1
            End If
        Loop Until lngIE = 0
        
        If intCount > 1 Then
            For p = 1 To (intCount - 1)
                lHwnd = FindWindow("IEFrame", vbNullString)
                Call GetWindowThreadProcessId(lHwnd, lProcess)
                lProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, lProcess)
                Call GetExitCodeProcess(lProcess, lExitCode)
                Call TerminateProcess(lProcess, lExitCode)
            Next p
        End If
        
    End Sub


    Sorry, I don't have Netscape so I don't know the hWnd (class,caption) of it.

  3. #3
    Guest
    Code:
    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 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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    
    Private Sub CloseWindow(ByVal lpClassName As String, ByVal lpWindowName As String)
        Dim hWnd_App As Long
        hWnd_App = FindWindowEx(0, 0, lpClassName, lpWindowName)
        If hWnd_App <> 0 Then
            SendMessage hWnd_App, wm_close, 0, 0
            DestroyWindow hWnd_App
        End If
    End Sub
    
    Private Sub Timer1_Timer()
        CloseWindow "CabinetWClass", "Control Panal"
        CloseWindow "CabinetWClass", "Printers"
        CloseWindow "IEFrame", vbNullString
        CloseWindow "Afx:400000:b:a0e:6:6c87", vbNullString
    End Sub

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