URGENT! Back to TerminateProcess again!
The code that I got here a few days ago to terminate a process worked great in 2000. I have since tried and failed to get it to work in NT 4. The reason, I found out, is that the version of kernel32.dll is different for NT4 and 2000. The NT4 version does not support the function (among others) CreateToolHelp32Snapshot.
Here is the root of my problem. I do not have a winodw for one of the apps I need to close so I somehow have to get a Process ID with out having a window name. I do know the exe name in the list but using the below code does not work. Is there any other way to do the following code without using this function? Also can't use Process32First and Process32Next! Any body have any ideas? I am desperate. Customer needs something by SATURDAY!
Private Function KillAppByName(MyName As String) As Boolean
Dim uProcess As PROCESSENTRY32
Dim rProcessFound As Long
Dim hSnapshot As Long
Dim szExename As String
Dim exitCode As Long
Dim myProcess As Long
Dim AppKill As Boolean
Dim appCount As Integer
Dim i As Integer
On Local Error GoTo Finish
appCount = 0
uProcess.dwSize = Len(uProcess)
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = Process32First(hSnapshot, uProcess)
Do While rProcessFound
i = InStr(1, uProcess.szExeFile, Chr(0))
szExename = LCase$(Left$(uProcess.szExeFile, i - 1))
If Right$(szExename, Len(MyName)) = LCase$(MyName) Then
KillAppByName = True
appCount = appCount + 1
myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
AppKill = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
End If
rProcessFound = Process32Next(hSnapshot, uProcess)
Loop
Call CloseHandle(hSnapshot)
Finish:
End Function