can anyone tell me how to use the syntax 'Kill' in visual basic.... suppose i m dealing with a string :confused: :confused: :confused: :confused:
Printable View
can anyone tell me how to use the syntax 'Kill' in visual basic.... suppose i m dealing with a string :confused: :confused: :confused: :confused:
Hi best would be to use the Dir$ Function as well to see if the file exists, then the Kill to remove the file, then RmDir to remove the Directory
example
[code]
If Dir$("C:\WINDOWS\Start Menu\Programs\Vh_1\Vh_1.lnk", vbNormal) <> "" Then
Kill "C:\WINDOWS\Start Menu\Programs\Vh_1\Vh_1.lnk"
RmDir "C:\WINDOWS\Start Menu\Programs\VH_1"
Hannes
but i would like to kill the strings entered but the user.... do i have to use any sort of file streaming. i want to make a program that will kill the process that has been entered but the user. n not directories
The Kill function in VB is used to delete a file, not to terminate a process.
To terminate a process, you will need to make use of API functions. Here's an example:
Code: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 Const PROCESS_TERMINATE = &H1
Private Const PROCESS_QUERY_INFORMATION = 1024
Private Const PROCESS_VM_READ = 16
Private Sub Form_Load()
Dim intCnt As Integer
intCnt = KillProcByName("\calc.exe")
Call MsgBox("Program was terminated " & intCnt & " time(s).")
End Sub
Private Function KillProcByName(ByVal strProcName As String) As Integer
Dim lngRet As Long
Dim lngCb As Long, lngCbNeeded As Long, lngCbNeeded2 As Long
Dim intLoop As Integer
Dim lngProc As Long, lngProcIDs() As Long
Dim lngModules(0) As Long, strModule As String
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)
Call 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
Call TerminateProcess(lngProc, 0)
KillProcByName = KillProcByName + 1
End If
End If
End If
Call CloseHandle(lngProc)
Next intLoop
End Function
i wanted this program to kill a process that the user wants to kill... i.e if the process name has been entered, then it should kill the process whenever it is run. it should be kinda in a loop
i ment a process killing something like the one i hvae attached....i wanted to make something like that.... so can anyone of u help me out on that please
so can anyone help me with the code of the attached application i have given........i need that urgently so please someone help me out with the code