Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing credentials to an IE popup window in VBScript

Posted on 2009-05-06
11
Medium Priority
?
6,541 Views
Last Modified: 2013-12-08
I want to pass credentials to an IE site I launch since it prompts me.  I don't want to pass my domain authentication because the authentication this uses is from a flatfile database so i want to just pass it a username and password.

the code below launches an IE site for something I'm automating on creating monitors and it prompts me for a username and password i would like to provide in the script.  Any ideas?
If numServer > 0 Then
	strLink= "http://ipmonitor.miamidade.gov:8080/em?form=importform&File=D%3A%5CConfigMonitors%5CMonitors.csv&File2=D%3A%5CConfigMonitors%5CRelationships.csv&Monitors=1&Groups=1&Profiles=1&Accounts=1&Reports=1&Jobs=1"
	Set objIExplorer = CreateObject("InternetExplorer.Application")
	objIExplorer.visible = True
	objIExplorer.navigate strLink
	Set objIExplorer = Nothing
End If

Open in new window

0
Comment
Question by:dachikzuki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 6

Expert Comment

by:Mark Pavlak
ID: 24320060
Autoit will do this but you have to register a dll on the machine it is executing.  I normally keep it out in a share and at the begining of the script regester it
0
 
LVL 3

Author Comment

by:dachikzuki
ID: 24320169
I've heard of autoit and some people here use that but it's a headache to keep up with all the different "tools".  Autoit would have made doing this in vbs a lot easier in general.  Is there any way of doing it with just vbs?
0
 
LVL 14

Expert Comment

by:BigBadWolf_000
ID: 24320177
See code below....
 

If numServer > 0 Then
	strUsername = "your user id"
	strPass = "your password"
	strLink= "your http:// link"
	Set objIExplorer = CreateObject("InternetExplorer.Application")
	objIExplorer.visible = True
	objIExplorer.navigate strLink
	
	While objIExplorer.Busy = True
	WScript.Sleep 100
	Wend
	While objIExplorer.ReadyState <> 4
	WScript.Sleep 100
	Wend
 
	objIExplorer.Document.all.username.value = strUsername
	objIExplorer.Document.all.password.value = strPass
	objIExplorer.Document.Forms(0).Submit()
	
	Set objIExplorer = Nothing
End If

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:BigBadWolf_000
ID: 24320212
in line 16 replace username with the "name" label for that field on site webpage
in line 17 replace password with the "name" label for that field on site webpage
in line 18 change Forms(0) to 0,1,2 or 3 depending on numer of forms on that website page
0
 
LVL 3

Author Comment

by:dachikzuki
ID: 24320309
Seems like exactly what i was looking for, however, the prompt is a windows prompt... it's not in a form.  It seems like it doesn't even get to that part of the code before the prompt comes out.   I attached a picture of the prompt so you can see what i mean.

prompt.bmp
0
 
LVL 3

Author Comment

by:dachikzuki
ID: 24320328
i put the code you gave me but it doesn't execute until after i answer the prompt i put in a pic above.  This prompt is the one i have to supply my credentials to.  
0
 
LVL 14

Expert Comment

by:BigBadWolf_000
ID: 24321753
The authentication occurs on the server, so I am not sure if we can get focus of the windows prompt box. So we will have to use the sendkey method. However, the problem with this and the lack of taking focus is that while this script runs ( a few seconds), you should not move mouse, keyboard or have any other app take focus....If you can live with this ...then the following script will work fine..see below

If numServer > 0 Then
	strUsername = "your user id"
	strPass = "your password"
	strLink= "your http:// link"
	Set objIExplorer = CreateObject("InternetExplorer.Application")
	objIExplorer.visible = True
	objIExplorer.navigate strLink
	
	Set WshShell = WScript.CreateObject("WScript.Shell")
	WshShell.SendKeys strUsername
	WScript.Sleep 100
	WshShell.SendKeys "{TAB}" 
	WScript.Sleep(100)
	WshShell.SendKeys strPass		
	WScript.Sleep 100
	WshShell.SendKeys "{TAB}"
	WScript.Sleep 100
	WshShell.SendKeys "{TAB}"
	WScript.Sleep 100
	WshShell.SendKeys "{ENTER}"
	
	Set objIExplorer = Nothing
	Set WshShell = Nothing
End If

Open in new window

0
 
LVL 14

Accepted Solution

by:
BigBadWolf_000 earned 2000 total points
ID: 24321834
Use the code below,,,,its a way to get focus,,,,,but not very reliable method,,,, if it does not work then remove the line.....

WshShell.AppActivate "Connect to ipmonitor.miamidade.gov"

If numServer > 0 Then
	strUsername = "your user id"
	strPass = "your password"
	strLink= "your http:// link"
	Set objIExplorer = CreateObject("InternetExplorer.Application")
	objIExplorer.visible = True
	objIExplorer.navigate strLink
	
	Set WshShell = WScript.CreateObject("WScript.Shell")
	WshShell.AppActivate "Connect to ipmonitor.miamidade.gov"
	WshShell.SendKeys strUsername
	WScript.Sleep 100
	WshShell.SendKeys "{TAB}" 
	WScript.Sleep(100)
	WshShell.SendKeys strPass		
	WScript.Sleep 100
	WshShell.SendKeys "{TAB}"
	WScript.Sleep 100
	WshShell.SendKeys "{TAB}"
	WScript.Sleep 100
	WshShell.SendKeys "{ENTER}"
	
	Set objIExplorer = Nothing
	Set WshShell = Nothing
End If

Open in new window

0
 
LVL 3

Author Comment

by:dachikzuki
ID: 24326598
You are the man!  That worked out very well for me.  I just had to add a small sleep timer before providing the username because it would race past it but it was exactly what i needed.  Thank you!
0
 
LVL 3

Author Closing Comment

by:dachikzuki
ID: 31578750
Excellent
0
 
LVL 14

Expert Comment

by:BigBadWolf_000
ID: 24331245
Your welcome :)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question