CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012

    Changing User Agent for webbrowser control

    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

    	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) {
    How I do it in VB.NET
    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
            uag = ("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.2a1pre) Gecko/20110323 Firefox/4.2a1pre")
    I'd really appreciate some help, thanks in advance.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: Changing User Agent for webbrowser control

    Your "C++" code has nothing to do with Visual C++, nor is it a native C++ code.
    You'd better ask your question in some of the .Net or in Managed C++/CLI forums
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.