Visual Basic Classic
--
Questions
--
Followers
Top Experts
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("internetExpl
create IE object but sometimes I see some people is using this, createprocess(sNull, "C:\program files\internet Explorer\iexplore.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
Sub IEconnect()
Set myIE = Nothing
Set myIE = CreateObject("InternetExplorer.Application")
Set myIE = New InternetExplorer
With myIE
.Visible = True
.navigate "www.example.com"
doevents
.quit
End With
End Sub
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I'll see if I can help you understand your situation. If you remember back when IE6 was around this didn't have the TAB features so each instance was contained in it's own process. However on IE7 and later when the TAB feature was introduced the instances are associated with TAB windows instead. For example you can see this behavior if you close all IE windows and open your first instance. You might notice "two" iexplorer.exe running but only "one" window instance. There is some hidden work that happens behind the scenes that when you launch new instances they are associated with a TAB instance. You might notice multiple "iexplorer.exe" instances if atleast one instance is still associated with the TAB so you might see these instances until you close "ALL" or the last instance of IE on the desktop then "ALL" (iexplorer.exe) should be released.
This behavior happens when there is multiple instances running and it's by design. I have already forwarded this information to Microsoft about 6 months ago and one of the developers responded with the following:
Quote:
"It's important to understand the IE8 includes a new multi-process architecture called Loosely Coupled IE. The IELaunchURL API should be returning the process ID of the "tab process" spawned by IELaunchURL, and not the PID of the parent "frame process" into which that tab process was created. This was a deliberate design decision, because callers are typically interested in the tab process ID, not the parent window."
Basically you might not see "iexplorer.exe" release all instances until "ALL" of them are closed on the desktop.
www.yahoo.com at Windows (not in mycode), and then the process is shown on Task manager. But when click X at right and top corner at IE windows, the display is gone and
its process also disappeared at the same time in Task manager. But when we createobj
IE windows from my VBA code and I click X at the IE windows corner or use code of myIE.quit
to let IE window disappear , the process is still shown on Task Manager.
And I keep repeating run and quit the IE window in my VAB, the same process id's memory
is never stopping to increase memory usage until I kill the process directly in Task Manager
If My program code will access the login page website for more than 30 times that will
create similar problem or issue above, that might be not good or the speed of running program
is getting slow gradually and unconsciously
In other words, there is any atlernative to kill the IE process from my code generated and
how I idendify which process of IE is from my VBA or not ? OR kill them all
by function of shell( cmd \ taskkill /F /im "iexplore.exe") in VBA that is not good
because I could not use IE for other applcation while running my VBA coding
Please advise if any suggestion
IE6 when you create instances you would see 10 processes running and 10 IE windows. It's because each instance was associated with it's own process.
IE7 and later you might see 5 (iexplorer.exe) running but you might have 10 windows running. When you close the window you may or may not see an instance of (iexplorer.exe) release. However when you open a new instance you may or may not see a new instance of (iexplorer.exe) be created. The (iexplorer.exe) instances are created and released independatley of the number of window instances you might see on the desktop. I don't know the actual number at which IE decides to spawn a new instance or at which point it decides to remove an (iexplorer.exe) instance.
If you really want to force them to ALL close I could help you, but it's a bug so long as you are using .Quit() on the correct instance you created. :)






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Should read as follows:
, but this is NOT a bug so long as you are using .Quit() on the correct instance you created. :)
and I run many time VBA program. ANd it will give a chance to virus since PID of the instance IE process is no change even running 1000 times of the program that is easily be attacked
I 've reviewed the website at http://www.ie-vista.com/tabs.html, now I understand what
you said about instance and tab defnition and the different from IE6 and IE7.
No matter in IE6 or IE7, If we know the process of ID fo IE we created in VBA, it means
we should be able to kill the process in VBA before start next run or next fresh VBA program
my.IE is only quit the instance or IE windows but doesn't kill the process at the time.
So, I think I need to do
Doing a code to record of PID of first instance IE, and kill it once program is done, that
is simple way to avoid any futuren or potential issue or problem. If the VBA code is running
100 times in ine day, that will have a lot issue if I don't solve this out described above first.
If possible, give some code or direction to record PID process and kill process
Please advise
Duncan
myIE.quit code is only quit the instance or IE windows but doesn't kill the process at the time.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Your only option here is to enumerate all (iexplorer.exe) processes and terminate them but you won't know which instance belongs to your created instance so you will in return be terminating an open instance you may have already creating using the automation. It's either use .Quit() method or terminate all of them on the system.
is created as parent process and other create page or object as child tab or process.
So if I keep running quit and access VBA program, it will accumulate all child process
to be associated with the first paraent process or other parent process . The answer
is we are Not sure those child process is assciated with which paranet process, it might be
my first instance process or old IE parent process,RIght ? So
we could not identify the exact association between child and parent process, so if we
want to kill the child process the only way is killing them all of IE in my computer instead, Right ?
TO verify this , I can test it and use tasklist to monitor PID change with different IE creat.
IF I don't mind the a little memory increase, just use quit() method to quit IE object that
is already safe to make sure All program is clean . Is that what you mean and suggestion to me
it works as your last email said.
the memory is stoped to increase
and keep same memory usage
for such process of IE. Proabably
.quit is working as we expect
What is wrong with the sentence
set myIE= New Internetexplorer
Most programmer is believing the
word "New" is re-start new IE
COuld explain it a little more about
"new" before we close this case
THanks, anyway, care about these
because my VBA code will run
the whole week without stopping
to collect data and without virus
interrupt. So now I am foucing
virus and security issue will stop
my VBA code running
THanks
Duncan






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Visual Basic Classic
--
Questions
--
Followers
Top Experts
Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.