How to enable inPrivate mode in the WebBrowser con

2019-01-19 12:46发布

问题:

I have to make a IE type browser with some extra features on it.

In Visual Studio, we have a component named "WebBrowser" that uses current IE browser installed in user's pc.

However, I am unable to find any property that enables access to the InPrivate mode I hoped would be exposed by control.

Is there a way to use InPrivate mode with the WebBrowser control, or would I have to make my own browser that supports this?

回答1:

According to EricLaw's answers on a related question, it sounds like this might not be possible.

You might be stuck making your own control or looking for an alternative one.



回答2:

Here's some code that will give you access to an InPrivate IE

Friend Function Open(Optional ByVal Url As String = "about:blank", Optional ByVal WindowState As ProcessWindowStyle = ProcessWindowStyle.Hidden) As WebBrowser
On Error Resume Next

Dim Start As New ProcessStartInfo
Dim Windows = New ShellWindowsClass
Dim Count = Windows.Count
Start.FileName = "iexplore.exe"
Start.Arguments = "-private -nomerge " & Url
If WindowState = ProcessWindowStyle.Hidden Then
  Start.WindowStyle = ProcessWindowStyle.Minimized
Else
  Start.WindowStyle = WindowState
End If
Process.Start(Start)

'Wait is my own class that waits for 10 secs
Wait.Reset()
Do
  If Windows.Count > Count Then Exit Do
Loop While Wait.Waiting

Browser = Windows(Count)
Browser.Visible = (WindowState <> ProcessWindowStyle.Hidden)
Return Browser
End Function