Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

schedule an asp page with userID and password protected auto run? 1

Status
Not open for further replies.

920506

Programmer
Jun 13, 2003
201
US
Hi all,
I know how to schedule an asp page to run on a daily base in IE. But is it possible to schedule an asp page with userID and password protected to run automatically?
I don't know how to pass ID and password to the program in that case?
Any clues?
Thank you.
Betty
 
It depends on how the username and password are requested. One method I have used in the past is to write a script (in VBScript as a vbs file) to instantiate an IE object then use the SendKeys method to send things correctly.
If the password is in a dialog then you can use a loop to wait until the password dialog comes up, send the correct keys, and submit that way.
If the password is in the page then it might be possible to use a form submission to supply the login informaiton. It basically comes down to how many steps you need to go through in order to get to the page that does what you need.

Not sure what you need here, but here's an example of the vbs script I mentioned above:
Code:
Option Explicit

Dim username, password, targetUrl
username = "myUsername"
password = "myPassword"
targetUrl = "[URL unfurl="true"]http://www.yourDomain.com/login.asp"[/URL]

Dim ie_app, WshShell, logged_in
Set WshShell = CreateObject("WScript.Shell")
Set ie_app = WScript.CreateObject("InternetExplorer.application","IE_")

ie_app.Navigate targetUrl
ie_app.Visible = true
ie_app.RegisterAsBrowser = TRUE

Dim sleepMax
sleepMax = 0
Do While WshShell.AppActivate("Enter Network Password") = FALSE
	WScript.Sleep 200
	sleepMax = sleepMax + 200
	If sleepMax > 20000 Then Exit Do
Loop

If sleepMax <= 20000 Then
	WshShell.SendKeys username & "{TAB}" & password & "{ENTER}"
End If
logged_in = true

Do While logged_in
	WScript.Sleep 1000
Loop

Sub IE_onQuit
	'action to take after completed - for instance logging success
	logged_in = false;
End Sub

Set WshShell = Nothing

-T

barcode_1.gif
 
Wow,
There is quite some window script information I need to consume. I never did before. thanks for your detailed instructions.
Basically, the userID and password is not in a form. It's authenticated access page set up by IIS. So when the page is requested, it will pop up a dialog form(default) asking for ID and password. It seems that I can use your script to handle that, right?
Do you have some basic resource links that I can refer for
WScript?
Thank you, Tarwn.
Betty
 
Actually, Tarwn, that is a nifty little piece... I have been educated today on something that I've not had to use previously but I think I can see a use for it with something I've got coming up, so this is beneficial...

Betty, try DevGuru for information on the WScript object.

------------------------------------------------------------------------------------------------------------------------
"I am not young enough to know everything."
Oscar Wilde (1854-1900)
 
Yep. The code I posted should be able to handle a dialog box. The magic there is:
Code:
sleepMax = 0
Do While WshShell.AppActivate("Enter Network Password") = FALSE
    WScript.Sleep 200
    sleepMax = sleepMax + 200
    If sleepMax > 20000 Then Exit Do
Loop

Basically the WshShell.AppActivate button returns a boolean indicating whether it could activate (bring to top even if minimized) a window with the given title. The title doesn't have to match exactly, it just tries to find the first match. So if your password box title showed something like "Please Enter Password Visitor #1234567" then you could feed "Please Enter Password" to AppActivate and it would match since the beginning of the popup title matches.
The sleep loop is there to give IE time to load the page and show the popup. Basically the loop tries to activate the login box. If it fails then it goes to sleep for 200 milliseconds, then tries again. The counter slowly increments to 20 seconds (20000ms) each time. If the counter reaches 20 seconds it escapes the loop and bypasses some later portions of the code to exit gracefully. The reasoning behind this is that you don't want this thing sitting in the background indefinately until a week later it sees a login box and tries to do it's magic on it. Additionally if you are executing on a schedule you could conceivably have tons of these still sleeping in the background, adding unnecessary load to the systemand causing all kins of havoc if several of them try to wakeup at the same time.

The best resource is Google :) If you search on the following lines, one at a time, you will learn more than you ever wantedto know about each one:
WScript.Shell
Shell.AppActivate - heres a good google cache of an MS link
WScript.CreateObject("InternetExplorer.application","IE_")

Those are probably the three core pieces of the script, withthe SendKeys method being referenced in that google link.


The only piece missing from this equation is some fiddling with Scheduled Tasks. To run this as a scheduled task you will want to setup a scheduled task to run WScript.exe (System32 folder I think) with the path to the script as an argument. If you need to pass additional arguments to your script you can add them in also and access those values from your script via WScript.arguments
If you need this to run more often then Scheduled Tasks gives you options for, then there is some trickery involved.
This is delving into anothe topic, but here goes.
Setup your scheduled task as if you wanted it to run Daily (shoudl be a radio option). Then edit your task and go to the tab that lets you define your schedule. Hit the advanced button and set your start time to 12AM, your end time to 11:59PM, and the run task every... to run every 5 minutes. Save it, execute your task. It will now run each day at midnight. Each time it runs it will set it's next run time to 5 minutes later, and it will not set a run time later than 11:59PM. Of course at 12:00am the process starts again.
Another example would be to make it run every 15 minutes during business hours, which would be a start time of 8AM, an end time of 5PM and a 'run every' of 15 minutes.

Hope this proves useful,
-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top