Results 1 to 14 of 14

Thread: kill process on a timer and run a exe ???

  1. #1

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34

    kill process on a timer and run a exe ???

    ok heres the problem
    i need a vb program to kill a process on a timer and then run a exe file after its killed the processes how can this be done

    i need it to kill

    iinstall.exe
    istsvc.exe

    and then delete the files inside or the folders

    c:\program files\istbar
    c:\program files\ISTsvc

    say after 2 minitues they have been deleted ,then run a reg file so it cleans the registrys
    Last edited by anddos; Oct 3rd, 2004 at 08:56 PM.

  2. #2

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34

    Unhappy

    anyone

  3. #3
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    If you just want it removed, you could use a command prompt... Outside of windows that is...
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  4. #4
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    VB Code:
    1. Option Explicit
    2. Private Const PROCESS_TERMINATE             As Long = &H1
    3. Private Const PROCESS_QUERY_INFORMATION     As Long = 1024
    4. Private Const PROCESS_VM_READ               As Long = 16
    5. Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
    6. Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, _
    7.                                                          ByVal bInheritHandle As Long, _
    8.                                                          ByVal dwProcId As Long) As Long
    9. Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, _
    10.                                                         ByVal cb As Long, _
    11.                                                         ByRef cbNeeded As Long) As Long
    12. Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, _
    13.                                                                ByVal hModule As Long, _
    14.                                                                ByVal ModuleName As String, _
    15.                                                                ByVal nSize As Long) As Long
    16. Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, _
    17.                                                              ByRef lphModule As Long, _
    18.                                                              ByVal cb As Long, _
    19.                                                              ByRef cbNeeded As Long) As Long
    20. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, _
    21.                                                           ByVal uExitCode As Long) As Long
    22.  
    23. Private Function KillProcByName(ByVal strProcName As String) As Long
    24.  
    25. Dim lngProc       As Long
    26. Dim lngProcIDs()  As Long
    27. Dim lngModules(0) As Long
    28. Dim strModule     As String
    29. Dim lngRet        As Long
    30. Dim lngCb         As Long
    31. Dim lngCbNeeded   As Long
    32. Dim lngCbNeeded2  As Long
    33. Dim intLoop       As Long
    34.  
    35.     lngCb = 8
    36.     lngCbNeeded = 96
    37.     Do While lngCb <= lngCbNeeded
    38.         lngCb = lngCb * 2
    39.         ReDim lngProcIDs(lngCb / 4) As Long
    40.         lngRet = EnumProcesses(lngProcIDs(0), lngCb, lngCbNeeded)
    41.     Loop
    42.     For intLoop = 1 To (lngCbNeeded / 4)
    43.         lngProc = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ Or PROCESS_TERMINATE, 0, lngProcIDs(intLoop))
    44.         If lngProc <> 0 Then
    45.             lngRet = EnumProcessModules(lngProc, lngModules(0), 1, lngCbNeeded2)
    46.             If lngRet <> 0 Then
    47.                 strModule = Space$(256)
    48.                 GetModuleFileNameExA lngProc, lngModules(0), strModule, Len(strModule)
    49.                 strModule = Left$(strModule, InStr(1, strModule, vbNullChar) - 1)
    50.                 If StrComp(Right$(strModule, Len(strProcName)), strProcName, vbTextCompare) = 0 Then
    51.                     TerminateProcess lngProc, 0
    52.                     KillProcByName = KillProcByName + 1
    53.                 End If
    54.             End If
    55.         End If
    56.         CloseHandle lngProc
    57.     Next intLoop
    58.  
    59. End Function
    60.  
    61. Private Sub Timer1_Timer()
    62.  
    63. Dim i As Long
    64.  
    65.     On Error Resume Next
    66.     KillProcByName "\iinstall.exe"
    67.     KillProcByName "\istsvc.exe"
    68.    
    69.     With File1
    70.         .Path = "c:\program files\istbar"
    71.         .Refresh
    72.         For i = 0 To .ListCount - 1
    73.             Kill .List(i)
    74.         Next i
    75.     End With
    76.     With File1
    77.         .Path = "c:\program files\ISTsvc"
    78.        
    79.         .Refresh
    80.         For i = 0 To .ListCount - 1
    81.             Kill .List(i)
    82.         Next i
    83.     End With
    84.     On Error GoTo 0
    85.  
    86. End Sub

  5. #5

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34
    thanks alot my friend i will give this a try
    its saying file1 compile error

    With File1
    varible not defined
    Last edited by anddos; Oct 4th, 2004 at 11:48 AM.

  6. #6
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    You need to add a filebox control. Looks like a letter icon on the toolbox.

  7. #7

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34
    nice one m8 , it compiled nicely :P
    i will let you know how the program goes
    thanks again

  8. #8

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34
    when i click on the exe i made is it suppose to kill the process's straight away or do i have to wait then it kills the process , dont think its killed them
    do i have to put anything in the filelist box i added as well
    also is it suppose to delete the folder

    C:\Program Files\ISTsvc
    and
    C:\Program Files\ISTbar

    or just the files inside it

    ok to clarify this process dosent get killed

    istsvc.exe
    and it cant be deleted till its been killed :/
    Last edited by anddos; Oct 4th, 2004 at 12:20 PM.

  9. #9
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    did you set the timer interval in properties. Set it to 1 or so.

  10. #10
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    Actually you'll need to change that to,

    VB Code:
    1. Private Sub Timer1_Timer()
    2.  
    3. Dim i As Long
    4.  
    5.     On Error Resume Next
    6.     KillProcByName "\iinstall.exe"
    7.     KillProcByName "\istsvc.exe"
    8.    
    9.     With File1
    10.         .Path = "c:\program files\istbar"
    11.         .Refresh
    12.         For i = 0 To .ListCount - 1
    13.             Kill "c:\program files\istbar\" & .List(i)
    14.         Next i
    15.     End With
    16.     With File1
    17.         .Path = "c:\program files\ISTsvc"
    18.        
    19.         .Refresh
    20.         For i = 0 To .ListCount - 1
    21.             Kill "c:\program files\istbar\" &.List(i)
    22.         Next i
    23.     End With
    24.     On Error GoTo 0
    25.  
    26. End Sub

  11. #11

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34
    did you set the timer interval in properties. Set it to 1 or so.


    all i did was paste the code that u said with the added new code u said for the timer part , i dont know where abouts to add 1 or 0 for the interval

    it looks like this


    Option Explicit
    Private Const PROCESS_TERMINATE As Long = &H1
    Private Const PROCESS_QUERY_INFORMATION As Long = 1024
    Private Const PROCESS_VM_READ As Long = 16
    Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
    Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, _
    ByVal bInheritHandle As Long, _
    ByVal dwProcId As Long) As Long
    Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, _
    ByVal cb As Long, _
    ByRef cbNeeded As Long) As Long
    Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, _
    ByVal hModule As Long, _
    ByVal ModuleName As String, _
    ByVal nSize As Long) As Long
    Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, _
    ByRef lphModule As Long, _
    ByVal cb As Long, _
    ByRef cbNeeded As Long) As Long
    Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, _
    ByVal uExitCode As Long) As Long

    Private Function KillProcByName(ByVal strProcName As String) As Long

    Dim lngProc As Long
    Dim lngProcIDs() As Long
    Dim lngModules(0) As Long
    Dim strModule As String
    Dim lngRet As Long
    Dim lngCb As Long
    Dim lngCbNeeded As Long
    Dim lngCbNeeded2 As Long
    Dim intLoop As Long

    lngCb = 8
    lngCbNeeded = 96
    Do While lngCb <= lngCbNeeded
    lngCb = lngCb * 2
    ReDim lngProcIDs(lngCb / 4) As Long
    lngRet = EnumProcesses(lngProcIDs(0), lngCb, lngCbNeeded)
    Loop
    For intLoop = 1 To (lngCbNeeded / 4)
    lngProc = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ Or PROCESS_TERMINATE, 0, lngProcIDs(intLoop))
    If lngProc <> 0 Then
    lngRet = EnumProcessModules(lngProc, lngModules(0), 1, lngCbNeeded2)
    If lngRet <> 0 Then
    strModule = Space$(256)
    GetModuleFileNameExA lngProc, lngModules(0), strModule, Len(strModule)
    strModule = Left$(strModule, InStr(1, strModule, vbNullChar) - 1)
    If StrComp(Right$(strModule, Len(strProcName)), strProcName, vbTextCompare) = 0 Then
    TerminateProcess lngProc, 0
    KillProcByName = KillProcByName + 1
    End If
    End If
    End If
    CloseHandle lngProc
    Next intLoop

    End Function

    Private Sub Form_Load()

    End Sub

    Private Sub Timer1_Timer()

    Dim i As Long

    On Error Resume Next
    KillProcByName "\iinstall.exe"
    KillProcByName "\istsvc.exe"

    With File1
    .Path = "c:\program files\istbar"
    .Refresh
    For i = 0 To .ListCount - 1
    Kill "c:\program files\istbar\" & .List(i)
    Next i
    End With
    With File1
    .Path = "c:\program files\ISTsvc"

    .Refresh
    For i = 0 To .ListCount - 1
    Kill "c:\program files\istbar\" & .List(i)
    Next i
    End With
    On Error GoTo 0

    End Sub

  12. #12

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34
    i just need to make the compiled exe kill its self
    say after 30 seconds of killing processes and deleting
    anyone know how to
    Last edited by anddos; Oct 9th, 2004 at 04:38 PM.

  13. #13

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34
    anyone

  14. #14

    Thread Starter
    Banned
    Join Date
    Sep 2004
    Location
    uk
    Posts
    34

    still stuck with this project

    ok anyone out there , i still need help witht his program
    its not killing the process istsvc.exe ...
    also i want the program to kill it self when its done killing the 2 exe's
    anyone know
    so far the code looks like this

    Option Explicit
    Private Const PROCESS_TERMINATE As Long = &H1
    Private Const PROCESS_QUERY_INFORMATION As Long = 1024
    Private Const PROCESS_VM_READ As Long = 16
    Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
    Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, _
    ByVal bInheritHandle As Long, _
    ByVal dwProcId As Long) As Long
    Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, _
    ByVal cb As Long, _
    ByRef cbNeeded As Long) As Long
    Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, _
    ByVal hModule As Long, _
    ByVal ModuleName As String, _
    ByVal nSize As Long) As Long
    Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, _
    ByRef lphModule As Long, _
    ByVal cb As Long, _
    ByRef cbNeeded As Long) As Long
    Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, _
    ByVal uExitCode As Long) As Long

    Private Function KillProcByName(ByVal strProcName As String) As Long

    Dim lngProc As Long
    Dim lngProcIDs() As Long
    Dim lngModules(0) As Long
    Dim strModule As String
    Dim lngRet As Long
    Dim lngCb As Long
    Dim lngCbNeeded As Long
    Dim lngCbNeeded2 As Long
    Dim intLoop As Long

    lngCb = 8
    lngCbNeeded = 96
    Do While lngCb <= lngCbNeeded
    lngCb = lngCb * 2
    ReDim lngProcIDs(lngCb / 4) As Long
    lngRet = EnumProcesses(lngProcIDs(0), lngCb, lngCbNeeded)
    Loop
    For intLoop = 1 To (lngCbNeeded / 4)
    lngProc = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ Or PROCESS_TERMINATE, 0, lngProcIDs(intLoop))
    If lngProc <> 0 Then
    lngRet = EnumProcessModules(lngProc, lngModules(0), 1, lngCbNeeded2)
    If lngRet <> 0 Then
    strModule = Space$(256)
    GetModuleFileNameExA lngProc, lngModules(0), strModule, Len(strModule)
    strModule = Left$(strModule, InStr(1, strModule, vbNullChar) - 1)
    If StrComp(Right$(strModule, Len(strProcName)), strProcName, vbTextCompare) = 0 Then
    TerminateProcess lngProc, 0
    KillProcByName = KillProcByName + 1
    End If
    End If
    End If
    CloseHandle lngProc
    Next intLoop

    End Function

    Private Sub Timer1_Timer()

    Dim i As Long

    On Error Resume Next
    KillProcByName "\iinstall.exe"
    KillProcByName "\istsvc.exe"

    With File1
    .Path = "c:\program files\istbar"
    .Refresh
    For i = 0 To .ListCount - 1
    Kill "c:\program files\istbar\" & .List(i)
    Next i
    End With
    With File1
    .Path = "c:\program files\ISTsvc"

    .Refresh
    For i = 0 To .ListCount - 1
    Kill "c:\program files\istbar\" &.List(i)
    Next i
    End With
    On Error GoTo 0

    End Sub
    Last edited by anddos; Oct 25th, 2004 at 02:57 AM.

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