Let us say that you have some product specifications stored on your intranet, and your paranoid network administrator requires authentication – the PNA was kind enough to provide a generic read only login.

You want to make life easy for your users, from MMS001 you want to press a button which will launch IE so you can see the product specifications seamlessly – automatically logging in. In this example, I am purely going to provide the authentication information, but you could potentially have the site choose a specific product or whatever you want.

One of the nice things about Internet Explorer is that it is just like MS Office, it’s COM enabled, so we can launch and control it through scripts or external programs.

In order to provide the log in information we need to determine the input box names for the Username and Passwords. You would also want to retrieve the Login button aswell in a real world example.

So below is what the login page looks like

Taking a look at the markup for this page, we see that the Username has an id of Login1_UserName. Password is Login1_Password.

2 Responses to Controlling an Internet Explorer Session from a JScript

Hi Scott, nice post! The technique reminds me of Greasemonkey for Firefox. Also, for the readers would be interested in setting the user and password directly in a URL, we can send any key/value pairs as parameters of an HTTP GET Request with LaunchTask or with ScriptUtil.Launch, for example: DashboardTaskService.Manager.LaunchTask(new Uri(“https://hostname/path?user=potatoit&password=potatoit”)) or ScriptUtil.Launch(“https://hostname/path?user=potatoit&password=potatoit”). LaunchTask will open a window inside of Smart Office whereas ScriptUtil.Launch will launch the operating system’s default URI handler, usually Internet Explorer. (Google Chrome in my case). That reduces the lines of code. Also, one can send parameters in an HTTP POST Request with an HttpWebRequest. Finally, a user can also create by themselves Links, Shortcuts, and use the Link Manager thus avoiding the need for a script. Thanks!

You’re 100% right, definitely take the KIS approach (Keep It Simple). If you don’t need fine grained control – like needing to process information on the page or potentially navigate multiple pages, then the solutions you have listed are a far better alternative…well…unless you have masochistic tendencies 😉