Asked by duncanb7
at 2024-06-19 05:35:57
Point:500 Replies:11 POST_ID:828349USER_ID:11059
Topic:
Visual Basic Programming;;
I have used following code of IEconnect Sub to access webiste, and everytime I run the code and finished webbroswering with myIE.quit, and then the IE windows will be disappeared right away I thought the IE windows is gone that mean IE process is also killed. But when I check Task manager to check whether IE process is gone or not, finally it is still there. So I wonder my.quit coding is just only delete the IE window instance and it dosen't kill the process. When I quit my VBA and then re-start the program again, the new IE process will use the preivous IE process ID to do same job event, and previous and new process is combined togehter as one acculumulate process and occupy memory is increasing. That is now I know if I run and quit my VBA program many times, the same IE process will occupy hung memory until the computer and windows hang up or creating some ghost effect. So I need to write a code and make sure to kill IE process exactly every time as I quit my program.
Question-1 I see some people use createobject("internetExplorer.Application" ) to
create IE object but sometimes I see some people is using this, createprocess(sNull, "C:program filesinternet Exploreriexplore.exe", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo). What is different besides
one is object and the other is process.
Question-2 COuld you provide some simple code to kill the IE process by processid everytime I run my code before quit my program that will help to make sure the process is gone completely ?
I have search one website, http://en.allexperts.com/q/Visual-Basic-1048/Kill-Process-VB-its-2.htm, describle these, but it is hard to follow up, in which we have seen a lot of Kernel32
and user32 lib usage such as follows , Why they are using ? Could you explain it whether
it is good way to kill a process
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Question-3, If quesion-2 is no answer, how about Alternatvie way to solve this out,
could use Shell command in VBA and run cmd tasklist to record
the pid when I create IE and then use the same pid to kill the process by taskkill /F /pid ?
Killing the accumulate un-used IE process that will help also to not be infected by virus
And I don't want kill the process in Task manage because we don't know when/what time we shoud do it. Programming including the kill process part is better.
Please advise
Duncan
Question-1 I see some people use createobject("internetExplorer.Application" ) to
create IE object but sometimes I see some people is using this, createprocess(sNull, "C:program filesinternet Exploreriexplore.exe", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo). What is different besides
one is object and the other is process.
Question-2 COuld you provide some simple code to kill the IE process by processid everytime I run my code before quit my program that will help to make sure the process is gone completely ?
I have search one website, http://en.allexperts.com/q/Visual-Basic-1048/Kill-Process-VB-its-2.htm, describle these, but it is hard to follow up, in which we have seen a lot of Kernel32
and user32 lib usage such as follows , Why they are using ? Could you explain it whether
it is good way to kill a process
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Question-3, If quesion-2 is no answer, how about Alternatvie way to solve this out,
could use Shell command in VBA and run cmd tasklist to record
the pid when I create IE and then use the same pid to kill the process by taskkill /F /pid ?
Killing the accumulate un-used IE process that will help also to not be infected by virus
And I don't want kill the process in Task manage because we don't know when/what time we shoud do it. Programming including the kill process part is better.
Please advise
Duncan