title: Changing the user agent of the WebBrowser control
body: <p>I am trying to change the UserAgent of the WebBrowser control in a Winforms application.</p>
  
  <p>I have successfully achieved this by using the following code:</p>
  
  <pre><code>[DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
  private static extern int UrlMkSetSessionOption(
      int dwOption, string pBuffer, int dwBufferLength, int dwReserved);
  
  const int URLMON_OPTION_USERAGENT = 0x10000001;
  
  public void ChangeUserAgent()
  {
      List&lt;string&gt; userAgent = new List&lt;string&gt;();
      string ua = "Googlebot/2.1 (+http://www.google.com/bot.html)";
  
      UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, ua, ua.Length, 0);
  }
  </code></pre>
  
  <p>The only problem is that this only works once. When I try to run the ChangeUserAgent() method for the second time it doesn't work. It stays set to the first changed value. This is quite annoying and I've tried everything but it just won't change more than once.</p>
  
  <p>Does anyone know of a different, more flexible approach?</p>
  
  <p>Thanks</p>