Results 1 to 12 of 12

Thread: How to kill the process?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    How to kill the process?

    I try to delete the folder..but cannot because another program is using the files. So how I can release the folder or kill the process?

  2. #2

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to kill the process?

    I know the program that use the folder.. The program name is ArcGIS.exe, I also know the folder location I tying to kill the process.

  4. #4
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: How to kill the process?

    vb Code:
    1. Const PROCESS_ALL_ACCESS = &H1F0FFF
    2. Const TH32CS_SNAPPROCESS As Long = 2&
    3.  
    4. Private Type PROCESSENTRY32
    5.     dwSize As Long
    6.     cntUsage As Long
    7.     th32ProcessID As Long
    8.     th32DefaultHeapID As Long
    9.     th32ModuleID As Long
    10.     cntThreads As Long
    11.     th32ParentProcessID As Long
    12.     pcPriClassBase As Long
    13.     dwFlags As Long
    14.     szexeFile As String * 260
    15. End Type
    16.  
    17. Private Declare Function OpenProcess Lib "kernel32.dll" ( _
    18.     ByVal dwDesiredAccess As Long, _
    19.     ByVal blnheritHandle As Long, _
    20.     ByVal dwAppProcessId As Long _
    21. ) As Long
    22.  
    23. Private Declare Function ProcessFirst Lib "kernel32.dll" Alias "Process32First" ( _
    24.     ByVal hSnapshot As Long, _
    25.     uProcess As PROCESSENTRY32 _
    26. ) As Long
    27.  
    28. Private Declare Function ProcessNext Lib "kernel32.dll" Alias "Process32Next" ( _
    29.     ByVal hSnapshot As Long, _
    30.     uProcess As PROCESSENTRY32 _
    31. ) As Long
    32.  
    33. Private Declare Function CreateToolhelpSnapshot Lib "kernel32.dll" Alias "CreateToolhelp32Snapshot" ( _
    34.     ByVal lFlags As Long, _
    35.     lProcessID As Long _
    36. ) As Long
    37.  
    38. Private Declare Function TerminateProcess Lib "kernel32.dll" (ByVal ApphProcess As Long, _
    39.     ByVal uExitCode As Long _
    40. ) As Long
    41.  
    42. Private Declare Function CloseHandle Lib "kernel32.dll" ( _
    43.     ByVal hObject As Long _
    44. ) As Long
    45.  
    46. Public Sub KillProcess(NameProcess As String)
    47.     Dim uProcess  As PROCESSENTRY32
    48.     Dim RProcessFound As Long
    49.     Dim hSnapshot As Long
    50.     Dim SzExename As String
    51.     Dim ExitCode As Long
    52.     Dim MyProcess As Long
    53.     Dim AppKill As Boolean
    54.     Dim AppCount As Integer
    55.     Dim i As Integer
    56.     Dim WinDirEnv As String
    57.        
    58.     If NameProcess <> "" Then
    59.         AppCount = 0
    60.        
    61.         uProcess.dwSize = Len(uProcess)
    62.         hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    63.         RProcessFound = ProcessFirst(hSnapshot, uProcess)
    64.        
    65.         Do
    66.             i = InStr(1, uProcess.szexeFile, Chr(0))
    67.             SzExename = LCase$(Left$(uProcess.szexeFile, i - 1))
    68.             WinDirEnv = Environ("Windir") + "\"
    69.             WinDirEnv = LCase$(WinDirEnv)
    70.            
    71.             If Right$(SzExename, Len(NameProcess)) = LCase$(NameProcess) Then
    72.                 AppCount = AppCount + 1
    73.                 MyProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
    74.                 AppKill = TerminateProcess(MyProcess, ExitCode)
    75.                 Call CloseHandle(MyProcess)
    76.             End If
    77.             RProcessFound = ProcessNext(hSnapshot, uProcess)
    78.         Loop While RProcessFound
    79.         Call CloseHandle(hSnapshot)
    80.     End If
    81. End Sub
    82.  
    83. Private Sub Command1_Click()
    84.     KillProcess "notepad.exe"
    85. End Sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to kill the process?

    I think I not kill the process.. I would like to unlock or release the folder path location from used by other program.

    KillProcess "C:\Program Files\ArcGIS\Bin\ArcMap.exe"

  6. #6

  7. #7
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to kill the process?

    Quote Originally Posted by matrik02
    I think I not kill the process.. I would like to unlock or release the folder path location from used by other program.

    KillProcess "C:\Program Files\ArcGIS\Bin\ArcMap.exe"
    Go to Command prompt and type Taskkill /IM ProcessNAme

    In your case

    Taskkill /IM ArcGIS.exe or Taskkill /IM ArcGIS*

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to kill the process?

    Quote Originally Posted by Dungeon Keeper
    Go to Command prompt and type Taskkill /IM ProcessNAme

    In your case

    Taskkill /IM ArcGIS.exe or Taskkill /IM ArcGIS*
    Can this done using VB code Without using command prompt

  9. #9
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to kill the process?

    Why not,

    Code:
    Shell "c:\windows\system32\taskkill.exe /IM ArcGIS*",vbHide
    vbHide is so the Command prompt window will be hidden

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to kill the process?

    Have API need to use the code because it used Shell.

  11. #11
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to kill the process?

    Quote Originally Posted by matrik02
    Have API need to use the code because it used Shell.
    Shell is VB6 function its not API

  12. #12

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