How do I change the user agent for the embedded web browser's process in C++?
Looking for a way to do it so the user agent is set for the entire time (multiple hyperlink clicks).
I know how to do it in VB.NET but starting out with C++ and it's an essential part of my project. Tried looking into UrlMkSetSessionOption but didn't understand it.
My C++ code so far
Code:
private: System::Void webBrowser1_DocumentCompleted(System::Object^ sender, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^ e) {
this->webBrowser1->ScriptErrorsSuppressed = true;
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
this->webBrowser1->Navigate("http://whatsmyuseragent.com");
}
};
}
How I do it in VB.NET
Code:
Private Property uag As String <DllImport("urlmon.dll", CharSet:=CharSet.Ansi)> _ Private Shared Function UrlMkSetSessionOption(ByVal dwOption As Integer, ByVal pBuffer As String, ByVal dwBufferLength As Integer, ByVal dwReserved As Integer) As Integer End Function Const URLMON_OPTION_USERAGENT As Integer = &H10000001 Public Function ChangeUserAgent(ByVal Agent As String) UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, Agent, Agent.Length, 0) #End Function
Then
uag = ("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.2a1pre) Gecko/20110323 Firefox/4.2a1pre")
ChangeUserAgent(uag
I'd really appreciate some help, thanks in advance.