Hi,
I need start IE in new window without addressbar, status bar but I cannot use kiosk mode (I need defined window size).
I need to know the processID of the IE process also.

I have 2 different codes:

System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "C:\Program Files\Internet Explorer\IEXPLORE.EXE";
p.StartInfo.Arguments = "http://google.cz";
p.Start();
int pid = p.Id;

This code starts the new IE window and returns its PID, but it cannot hide address bar, status bar and so on..


The second code:

System.Type oType = System.Type.GetTypeFromProgID("InternetExplorer.Application");
object o = System.Activator.CreateInstance(oType);
o.GetType().InvokeMember("menubar", System.Reflection.BindingFlags.SetProperty, null, o, new object[] { 0 });
o.GetType().InvokeMember("toolbar", System.Reflection.BindingFlags.SetProperty, null, o, new object[] { 0 });
o.GetType().InvokeMember("statusBar", System.Reflection.BindingFlags.SetProperty, null, o, new object[] { 0 });
o.GetType().InvokeMember("addressbar", System.Reflection.BindingFlags.SetProperty, null, o, new object[] { 0 });
o.GetType().InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, o, new object[] { true });

It starts IE window without address bar, status bar.. but I don't know, howto find processID of the IE instance..

Please help..

Regards,
Petr

Dani AI

Generated

A practical way to get what wanted (a sized IE window with chrome hidden) while also being able to identify the process is to combine a process-based launch (to force a new IE process) with the automation API (to hide toolbars and size the window) and then map the browser COM object back to the process ID.

  • Start a true IE process that will not be opportunistically merged into an existing frame process by launching iexplore.exe with the -noframemerging switch and your URL. This forces a separate frame/tab process instead of reusing an existing one. (superuser.com)

  • Use the ShellWindows collection to find the new browser automation object (IWebBrowser2) and read its HWND value; the IWebBrowser2 HWND gives the top-level window handle so you can correlate windows and COM objects. (learn.microsoft.com)

  • Convert that HWND into a PID with the Win32 GetWindowThreadProcessId API and match it to the process you started. Once you have the matching IWebBrowser2 object you can set AddressBar, MenuBar, ToolBar, StatusBar and the window Left/Top/Width/Height properties from the COM object (or use SetWindowPos if you prefer). (learn.microsoft.com)

Notes and pitfalls:

  • There is a race between starting the process and the ShellWindows collection exposing the new object; poll with a short timeout and match on HWND/PID or LocationURL.
  • The COM-created InternetExplorer.Application approach that and tried will often end up hosted in an existing IE frame (so it may not produce a new PID) because of frame-process behavior unless you disable merging as above. (superuser.com)
  • Internet Explorer is deprecated/removed on modern Windows; on recent systems IE may be disabled or redirected to Edge (IE mode behaves differently), so test on the target machines and consider hosting a WebBrowser control or using Edge/IE-mode alternatives for long-term support. (support.microsoft.com)

This approach addresses ’s PID concern (start a non-merged process, find its HWND via IWebBrowser2, then use GetWindowThreadProcessId) while still letting you hide the chrome and set exact window size via the browser automation properties.

Recommended Answers

All 2 Replies

It hasn't any process created for it!! it attached to your application. but also if you terminate the application it doesn't (fuzzy) read in GetTypeFromProgID documentation

I know this is an ugly bump but I've been trying to figure out this exact scenario with still no resolution. I've shorten up the code based off various google searches with the result as:

Type oType = Type.GetTypeFromProgID("InternetExplorer.Application");
if (oType != null)
{
    SHDocVw.InternetExplorer ie = Activator.CreateInstance(oType) as SHDocVw.InternetExplorer;

    if (ie != null)
    {
        object oEmpty = String.Empty;
        object oURL = "http://www.somewhere.com";
        ie.AddressBar = false;
        ie.MenuBar = false;
        ie.ToolBar = 0;
        ie.Visible = true;
        ie.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty);
    }
}

To get the process id, I have found it possible to use:

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint lpdwProcessId);

However, I've found that using the Activator.CreateInstance will not create new processes. For example, let's say you have an IE browser open already (outside this app) with process id 1000. If this code is ran to launch another browser window, there is indeed a new window separate from the already opened window however it has the same process id of 1000. If you were to do a Process.Close() on id 1000, it would close both IE windows. Is there any way to do a CreateInstance having it create a new instance with a new process id?

Thanks,
-Nelis

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.