I got on with this, and found:
The problem with the code before, is that WM_CLOSE does not work for
IE. Dont know why, just is so.
Found this, which works in Delphi, so I portaged it.
My problem is that "f = Process32First(hSnap, proc)" is 0, while in
Delphi: "if Process32First(processSnapshot, processEntry) then"
works. To me it should be the same. Large parts of the VB code is
found here, as the declarations (easier that way). Still, something
goes wrong... what?
The delphi code is
processSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
processEntry.dwSize := SizeOf(processEntry);
if Process32First(processSnapshot, processEntry) then
etc... btw this works...
Which translates into:
Dim f As Long, sname As String
Dim hSnap As Long, proc As PROCESSENTRY32
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If hSnap <> hNull Then
proc.dwSize = Len(proc)
f = Process32First(hSnap, proc)
Do While f ' <- alway false
sname = StrZToStr(proc.szExeFile)
If sname = "iexplore.exe" Then
ProcessHandle = OpenProcess(PROCESS_TERMINATE, 0,
proc.th32ProcessID)
Call TerminateProcess(ProcessHandle, 0)
End If
f = Process32Next(hSnap, proc)
Loop
'CloseHandle hSnap
End If
Remember to add:
Public Declare Function Process32First Lib "kernel32" ( _
ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32" ( _
ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function CloseHandle Lib "Kernel32.dll" ()
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" ( _
ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Public Declare Function OpenProcess Lib "Kernel32.dll" _
(ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, _
ByVal dwProcId As Long) As Long
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long ' This process
th32DefaultHeapID As Long
th32ModuleID As Long ' Associated exe
cntThreads As Long
th32ParentProcessID As Long ' This process's parent process
pcPriClassBase As Long ' Base priority of process threads
dwFlags As Long
szExeFile As String * 260 ' MAX_PATH
End Type
Function StrZToStr(s As String) As String
StrZToStr = Left$(s, Len(s) - 1)
End Function
|