title: Changing the user agent using urlmon.dll
body: <p>While looking for a way to change the user agent string for the webBrowser control, I found this nifty method:</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 static void ChangeUserAgent(string Agent)
      {
          UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, Agent, Agent.Length, 0);
      }
  </code></pre>
  
  <p>Basically, I needed a way to change the user agent until I want to change it again.</p>
  
  <p>The usual:</p>
  
  <pre><code>webBrowser1.Navigate ("http://www.whatsmyuseragent.com", "_self" , null, "User-Agent: Luke's Web Browser");
  </code></pre>
  
  <p>Only works for one request.</p>
  
  <p>However, I keep reading everywhere that the first method only works once per session. In my case, it works as many times as I want it to. So my guess is that this is related to the instance of Internet Explorer on the computer?</p>
  
  <p>So my questions are:</p>
  
  <ul>
  <li>What version does the end user need to have installed on their computer for this method to work as intended? IE. change as much as I want.</li>
  <li>Since this is related to the Internet Explorer installed on the computer, does changing the user agent in my application effect the browser?</li>
  <li>If the user has Internet Explorer open, will this method still work?</li>
  </ul>
  
  <p>Thanks!</p>