Results 1 to 4 of 4

Thread: Closing Another Program

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    how can i close another program from my program. i used the closewindow api but it didnt work.

  2. #2
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    You Should try to use tanother API here is one that works fine with me : (warning - It c loses any application u specify without asking save yes/no/cancel)

    Code:
    Public Sub ForceAppClosed(ByVal lHwnd As Long)    'Force the App to Shutdown
    
    Dim lPID As Long
    Dim lCode As Long    'Get the Windows ProcessID
    Call GetWindowThreadProcessId(lHwnd, lPID)    'Get a Handle to the Process
    lPID = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPID)    'Get the Processes Exit Cod
    Call GetExitCodeProcess(lPID, lCode)    'Tell the Process to Terminate
    Call TerminateProcess(lPID, lCode)
    End Sub
    Declarations :
    Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) 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 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

    - regards -
    - razzaj -

  3. #3
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    You Should try to use tanother API here is one that works fine with me : (warning - It c loses any application u specify without asking save yes/no/cancel)

    Code:
    Public Sub ForceAppClosed(ByVal lHwnd As Long)    'Force the App to Shutdown
    
    Dim lPID As Long
    Dim lCode As Long    'Get the Windows ProcessID
    Call GetWindowThreadProcessId(lHwnd, lPID)    'Get a Handle to the Process
    lPID = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPID)    'Get the Processes Exit Cod
    Call GetExitCodeProcess(lPID, lCode)    'Tell the Process to Terminate
    Call TerminateProcess(lPID, lCode)
    End Sub
    Declarations :
    Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) 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 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

    - regards -
    - razzaj -

  4. #4
    New Member
    Join Date
    Apr 2000
    Posts
    5
    Hi,

    I have tried your way to close apps which are started with shell32 commnad. It works for most applications but not for Miscrosoft Imaging, where I found process ID will be reset to zero when OpenProcess is run.

    Pls advise.

    Brgds,/Albert

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