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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a window (very basic newbie question)

Status
Not open for further replies.

Oomingmak

Technical User
Sep 26, 2000
2
0
0
GB
I know absolutely nothing about programming at all (although I am a competent PC user).

My ISP requires a second web page based log in after dial-up networking has connected, and I have found a VBscript that automates this process (it fills in username, password and submits the form).

However the php login page causes a pop up window to appear upon successful login, and I would like to kill this browser pop up by adding a VBScript command to close it.

I know its a ridiculously basic thing to ask, but I have been searching through on line help files and tutorials on the net for about 7 or 8 hours now and STILL can't find a way to do this. Even the supposedly easiest of beginners guides dont give the kind of examples that i am looking for (its all Arrays, Variants and Subtypes etc. which is total overkill for for my purposes).

All I want to do is close a window !!!

After this pop up window is closed the 'Auto Disconnect' dialog will pop up asking me if I want to disconnect from the Internet (because at that point there are no IE windows open) so I would also like the script to hit the 'Stay Connected' button.

I have seen a command in one of the tutorials that closes a window but have no idea how to get the script know which window I want closed, or how to get it to press the correct button in the auto disconnect dialog.

Can anyone please help? (apologies for the ridiculously basic nature of the question)
 
Hi Oomingmak,

I think you may be able to send some keystrokes to the active window by using the SENDKEYS command as below. I got this script from somewhere so apologies to its author for undue recognition :) I'm also a newbie but find this forum and the likes of extremely useful.

This script runs NOTEPAD.EXE from the Windows root directory, waits 3 seconds and then closes the open window with an ALT+F4 and displays a message box when it's finished. If there's an underscore on one of the letters in the "Stay Connected" dialog you should also be able to send it a keystroke {%S} or whatever.

Hope this helps.

Dim oWSHShell
Dim oWSHEnvironment

Set oWSHShell = WScript.CreateObject("WScript.Shell")
Set oWSHEnvironment = oWSHShell.Environment("SYSTEM")

oWSHShell.Run oWSHEnvironment("WINDIR") & "\NOTEPAD.EXE", 3, False 'Open notepad.
WScript.Sleep 3000 'Wait three seconds.
oWSHShell.SendKeys "%{F4}" 'Send ALT+F4 to close the notepad program
Set oWSHShell = Nothing
MsgBox "Done!" [sig][/sig]
 
Thanks Budmore,

This is just the kind of info that I have been looking for. I tried out the SendKeys function and it works (it closes pop up window and then later presses 'Stay Connected' button on the Auto Disconnect dialog).


However, my solution is not very elegant due to the long wait states that I have to use.

This is because I dont know how to do the following:

a) Test for the pop up windows existance (make the script wait until window is has popped up and then send keys as soon as it is detected. (Maybe also make the pop up invisible so that wait state can be a bit longer but pop up wont be seen before it is closed).

b) Specifically select the pop up window so that keys are not inadvertantly sent to another active window (how would you select the window to send keys to close it if it is hidden?).

Can anybody tell me how to go about doing this please?




It seems as if useful examples of code such as the one that Budmore has given me are very hard to find. All the examples I have seen are useless Hello World scripts or scripts that simple open a program (although no one tells you how to close it after its been run). Then they go from that straight into Active X control etc. etc. LOL !


If anyone knows of a USEFUL beginners guide (ie properly commented real world code examples - not theoretical syntax examples) for such things as:

Move, copy, rename, delete a file or folder
Maximise, minimise, close, show, hide a window
Select a window, set focus to various elements in that window
and other such everyday function examples,

I would be very, very grateful for any links that you provide.

Cheers. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top