Results 1 to 3 of 3

Thread: How to Close Executable Programs with API Calls

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Windsor
    Posts
    100

    Question How to Close Executable Programs with API Calls

    I am calling executable program through shell API call with a VB6 Program . I can run any executable programs, but I do not know how to close them through API call. Do I have to have a different API call to close the applications?

    Please see API call function.

    Public Declare Function ShellExecute Lib "shell32.dll" Alias _
    "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
    String, ByVal lpszFile As String, ByVal lpszParams As String, _
    ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long


    ShellExecLaunchFile = ShellExecute(Scr_hDC, "Open", strPathFile, "", strOpenInPath, SW_SHOWNORMAL)


    Thanks,

    Naci

  2. #2
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    This will terminate all instances of a running application. MyName should be the .EXE of the program.

    VB Code:
    1. Public Function KillAppByName(MyName As String) As Boolean
    2.     Const PROCESS_ALL_ACCESS = 0
    3.     Dim uProcess As PROCESSENTRY32
    4.     Dim rProcessFound As Long
    5.     Dim hSnapshot As Long
    6.     Dim szExename As String
    7.     Dim exitCode As Long
    8.     Dim myProcess As Long
    9.     Dim AppKill As Boolean
    10.     Dim appCount As Integer
    11.     Dim i As Integer
    12. On Local Error GoTo Finish
    13.     appCount = 0
    14.    
    15.     Const TH32CS_SNAPPROCESS As Long = 2&
    16.    
    17.     uProcess.dwSize = Len(uProcess)
    18.     hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    19.     rProcessFound = ProcessFirst(hSnapshot, uProcess)
    20.    
    21.     Do While rProcessFound
    22.         i = InStr(1, uProcess.szexeFile, Chr(0))
    23.         szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
    24.         If Right$(szExename, Len(MyName)) = LCase$(MyName) Then
    25.             KillAppByName = True
    26.             appCount = appCount + 1
    27.             myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
    28.             AppKill = TerminateProcess(myProcess, exitCode)
    29.             Call CloseHandle(myProcess)
    30.         End If
    31.         rProcessFound = ProcessNext(hSnapshot, uProcess)
    32.     Loop
    33.  
    34.     Call CloseHandle(hSnapshot)
    35. Finish:
    36. End Function
    And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Windsor
    Posts
    100
    Hi brenaaro,

    I try to run KillAppByName but I got error like "user defined” type is not defined".

    Is there any way that you can send me complete function calls?

    Naci

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