Getting main window from launched process

S

siddharthkhare

Hi All,

I am launching a IE using following code.
=======================================================================
m_IeProcess = new Process();
m_IeProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
m_IeProcess = Process.Start("IExplore.exe","www.ABC.com");
=======================================================================

how do i get refrence to the InternetExplorer from the process.

only way i could do it is by iterating over the all windows as follows

===============================================================

m_Windows = new ShellWindows();
foreach(InternetExplorer ie in m_Windows)
{
if(ie != null && (IntPtr)ie.HWND ==
m_IeProcess.MainWindowHandle)
{
return ie;
}
}


=======================================================================

Qustion :
is there a way to get refrence to the internet explorer without using
shell window.

Process class has properties that return Mainwindow handle and caption
etc...but i do not see anything that returns the reference to the main
window itself.

I need the refrence to IE because i want to iterate through the window
object model.
I will be running this code as windows service and shell window does
not work in windows service that why i am looking at other ways to do
this.

SO is there a way to get the refrence to IE from the lauched process
or may be using a windows API that will work in windows service as
well?

Thanks
Siddharth
 
T

Tom Shelton

Hi All,

I am launching a IE using following code.
=======================================================================
m_IeProcess = new Process();
m_IeProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
m_IeProcess = Process.Start("IExplore.exe","www.ABC.com");
=======================================================================

how do i get refrence to the InternetExplorer from the process.

only way i could do it is by iterating over the all windows as follows

===============================================================

m_Windows = new ShellWindows();
foreach(InternetExplorer ie in m_Windows)
{
if(ie != null && (IntPtr)ie.HWND ==
m_IeProcess.MainWindowHandle)
{
return ie;
}
}

=======================================================================

Qustion :
is there a way to get refrence to the internet explorer without using
shell window.

Process class has properties that return Mainwindow handle and caption
etc...but i do not see anything that returns the reference to the main
window itself.

I need the refrence to IE because i want to iterate through the window
object model.
I will be running this code as windows service and shell window does
not work in windows service that why i am looking at other ways to do
this.

SO is there a way to get the refrence to IE from the lauched process
or may be using a windows API that will work in windows service as
well?

Thanks
Siddharth

Well, your not going to get a .net reference from the process
class... All your gong to get is the MainWindow handle (you could
probably wrap it in an instance of NativeWindow). What exactly are
you trying to accomplish? I have a feeling there is a much better
way...
 
S

Sheng Jiang[MVP]

Use CLSID_INTERNETEXPLORER to create a com object. You can all its methods
using late binding, or create an early binding class.
 
S

siddharthkhare

Thanks Tom...

What i need to do is programmatically open a we site in a IE and get
reference to its document object.

Assume i need to count the number of controls on the opened web
page....

Can you elaborate on "could probably wrap it in an instance of
NativeWindow"


And whatever approach I use should work in windows service also unlike
"ShellWindow()'

Thanks
Siddharth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top