Changing User Agent for webbrowser control

This is a discussion on Changing User Agent for webbrowser control within the Windows Programming forums, part of the Platform Specific Boards category; How do I change the user agent for the embedded web browser's process in C++? Looking for a way to ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    1

    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

    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.

  2. #2
    and the hat of Marriage Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    178
    The User-Agent is specified in the header of the HTTP request isn't it? So... you don't... change it, you just specify what you want it to be when you're making a request.

    Also... what... is that? That's not C++. That's... I don't know. o3o
    How to ask smart questions

    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesWritten);

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,461
    the first part is C++/CLI - the .Net variant of C++, and the second is Visual Basic. neither language is really supported on this forum. you might try the tech board.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    Moved to windows board
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    and the hat of Marriage Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    178
    Quote Originally Posted by Elkvis View Post
    the first part is C++/CLI - the .Net variant of C++
    Is that what Managed C++ is? Hm.

    EDIT:: Read a little. Managed C++ is the deprecated older version of C++/CLI.
    How to ask smart questions

    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesWritten);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open exrternal file in a WebBrowser control
    By rebeccar in forum C# Programming
    Replies: 3
    Last Post: 05-26-2010, 09:46 AM
  2. WebBrowser control
    By Overlord in forum Windows Programming
    Replies: 3
    Last Post: 12-21-2008, 05:06 AM
  3. erase cookies cookie from webbrowser control
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 07-23-2007, 01:28 PM
  4. hide scipt errors/warnings in webbrowser control
    By hanhao in forum Windows Programming
    Replies: 1
    Last Post: 06-28-2007, 10:44 AM
  5. Massive - Agent based crowd control AI
    By Mario F. in forum General AI Programming
    Replies: 4
    Last Post: 08-20-2006, 03:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21