Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

_SetUserAgent() Change IE COM Session User Agent


  • Please log in to reply
8 replies to this topic
TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

_SetUserAgent() sets a customized User Agent that identifies the IE COM object.

Tested and working on IE 7, 8.

To change the User Agent in later versions of IE, see the posts below

Typical default User Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0

Call the function after creating the COM Object and before the Navigate() or Navigate2() methods.
Or you can call it from a BeforeNavigate2() Event or Class Event.

Examples:

; Switch from IE to Safari User Agent
_SetUserAgent("Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27")
; Switch from IE to Opera User Agent
_SetUserAgent("Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14")
; Fun nonsense 
_SetUserAgent("kittens like this User Agent")

Function:

_SetUserAgent(dwOpt) 
{
    ; Discovered by Inthemist
    ; AutoIt >> AutoHokey port by TLM
    ; ANSI fix by GeekDude

    DllCall("urlmon.dll\UrlMkSetSessionOption"
    	   , uint, 0x10000001
    	   , aStr, dwOpt
   	   , uint, StrLen(dwOpt)
    	   , uint, 0)
}

This basically changes the User Agent for an IE object session
as Navigate/2() headers only work once.

You can verify the User Agent by navigating to: http://whatsmyuseragent.com


Posted Image

don't duplicate, iterate!


stemsmit
  • Members
  • 17 posts
  • Last active: Feb 06 2015 11:17 PM
  • Joined: 16 May 2013

Is this compatible with IE10 and IE11? I am unable to get it to work.



TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

Where are you placing the function call?

Please show your code in code tags ty


Posted Image

don't duplicate, iterate!


stemsmit
  • Members
  • 17 posts
  • Last active: Feb 06 2015 11:17 PM
  • Joined: 16 May 2013

Activated via a hotkey 

wb := ComObjCreate( "InternetExplorer.Application" )
wb.Visible := True
_SetUserAgent("iPhone")
;Msgbox, % wb.navigator.userAgent
;wb.document.parentWindow.navigator.userAgent := "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A405 Safari/8536.25"


If(ErrorLevel)
  Msgbox % ErrorLevel
else
  wb.Navigate("http://whatsmyuseragent.com")


return

The function:

_SetUserAgent(device){
  UAString := device == "iPhone" ? "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A405 Safari/8536.25":""
  DllCall("urlmon.dll\UrlMkSetSessionOption"
           , uint, 0x10000001
           , aStr, UAString
           , uint, StrLen(UAString)
           , uint, 0)
}


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

let me check this out...


Posted Image

don't duplicate, iterate!


stemsmit
  • Members
  • 17 posts
  • Last active: Feb 06 2015 11:17 PM
  • Joined: 16 May 2013

I found an article that may be relative to this: http://blogs.msdn.co...ternatives.aspx



stemsmit
  • Members
  • 17 posts
  • Last active: Feb 06 2015 11:17 PM
  • Joined: 16 May 2013

After investigating further I was able to discover this which works for IE 10: 

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("http://whatsmyuseragent.com",0,0,0,"User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25")


joedf
  • Administrators
  • 986 posts
  • AutoHotkey Foundation
  • Last active: Nov 02 2019 08:38 PM
  • Joined: 20 May 2012
Interesting
Why ahkscript.org? - autohotkey.com is outdated

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

very nice! I couldn't for the life of me figure it out.

 

thank you so much


Posted Image

don't duplicate, iterate!