![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: May 2009
Posts: 6
OS: Vista, XP sevice pack 3
|
Using VBscript to call a window and close it.
I have a script that I am using to call a archive program. The script calls the programm sucessfully and runs the archive but I cant seem to get the script to close the program after the archive has completed. Below is the script itself. Any ideas?
Set objShell = CreateObject("WScript.Shell") objShell.LogEvent 0, "Archive.vbs - Beginning Archive Script Execution." objShell.Exec "c:\program files\FastPass\Archive.exe" Success = objShell.AppActivate("Archive") Wscript.Sleep 10000 objShell.SendKeys "%A" Wscript.Sleep 82800000 objShell.SendKeys "%{F4}" Last edited by CarlosL; 05-05-2009 at 09:41 AM. |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
title here
|
Re: Using VBscript to call a window and close it.
I have previous VBScript programming knowledge, but if this is a basic "Set" statement, then you should be able to end the statement with a "Close" command, so add to the end of your code:
Code:
objShell.close
__________________
|
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: May 2009
Posts: 6
OS: Vista, XP sevice pack 3
|
Re: Using VBscript to call a window and close it.
thanks for the input I will try it but this is the thing. In the code where it says
Wscript.Sleep 82800000 objShell.SendKeys "%{F4}" that statement in theory should send the F4 key after 24hrs as if someone were to be sitting at the keyboard. Not sure if you understood that but let me know. Thanks for the response and support. Any ideas will help. Thanks in advance. |
|
|
|
|
|
#4 (permalink) | |
|
TSF Enthusiast
Join Date: Mar 2009
Location: Portland, OR
Posts: 815
OS: MS-Dos 6.22 - Win7
|
Re: Using VBscript to call a window and close it.
Quote:
And after 23 hours the application might not be the foreground application any more, so I would send another AppActivate command to make sure it has focus, then send the ALT+F4. If the program generates a Pop-up to say its done, you'd need to OK that first, or send 2 ALT+F4 keystrokes. Does the program itself have a setting to exit when finished?
__________________
Microsoft MVP - Windows Desktop Experience Of course I know all the answers; I just don't always match the answers to the right questions. Rated R for Violence -- When your PC flies through a window, that's violent, right? |
|
|
|
|
|
|
#5 (permalink) |
|
Registered User
Join Date: May 2009
Posts: 6
OS: Vista, XP sevice pack 3
|
Re: Using VBscript to call a window and close it.
Thank you for your response. The program itself does not have a setting for exit when finished it is simply a status bar that is filled when completed. No pop up window saying finished gets generated.
I will try the suggestion of another AppActive command and see what happens, stay tuned for the response......Thanks again for the response it is much appreciated. |
|
|
|
|
|
#8 (permalink) |
|
TSF Enthusiast
Join Date: Mar 2009
Location: Portland, OR
Posts: 815
OS: MS-Dos 6.22 - Win7
|
Re: Using VBscript to call a window and close it.
Is the Status window just the progress bar with a OK button when it's done?
Can you actually close this window with ALT+F4, or by clicking the X in the upper right, or is that grayed out? For example, scrolling through the Event Viewer Details will produce the attached dialog. It can't be closed with ALT+F4 or the Close button, you have to click Yes or No. In this case, you could send ALT+Y or ALT+N (Note that Y and N are underlined, showing that they work with the ALT key) Maybe you can send ALT+O if it's an OK button. HTH Jerry
__________________
Microsoft MVP - Windows Desktop Experience Of course I know all the answers; I just don't always match the answers to the right questions. Rated R for Violence -- When your PC flies through a window, that's violent, right? |
|
|
|
|
|
#9 (permalink) |
|
Registered User
Join Date: May 2009
Posts: 6
OS: Vista, XP sevice pack 3
|
Re: Using VBscript to call a window and close it.
The Alt+F4 command works no problem....If I set the sleeptime for like 5, 10, or even 20 mins it works fine its just that after 23 or 24 hours it doenst see the sendkey command for alt+F4...
It has something to do with the long period of time that the program sits there... I tried the AppActive command like you suggested but still no go.. I appreciate your help.. |
|
|
|
|
|
#10 (permalink) |
|
TSF Enthusiast
Join Date: Mar 2009
Location: Portland, OR
Posts: 815
OS: MS-Dos 6.22 - Win7
|
Re: Using VBscript to call a window and close it.
I'm guessing that ALT+F4 still works after 24 hours if you do it by hand?
Might want to add some Wscript.echo statements before and after the sleep and sendkeys statements, see if the script is actually waking up and sending the AppActivate and ALT+F4
__________________
Microsoft MVP - Windows Desktop Experience Of course I know all the answers; I just don't always match the answers to the right questions. Rated R for Violence -- When your PC flies through a window, that's violent, right? |
|
|
|
![]() |
| Thread Tools | |
|
|