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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 05-05-2009, 09:18 AM   #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.
CarlosL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 05-06-2009, 02:42 AM   #2 (permalink)
title here
 
TJ Belfiore's Avatar
 
Join Date: Mar 2009
Location: 530
Posts: 3,517
OS: 7 x64, XP x32


Blog Entries: 1
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
__________________


Read more about ProgrammersDilemma in my latest blog, here.
TJ Belfiore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-11-2009, 02:38 PM   #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.
CarlosL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-14-2009, 10:53 PM   #4 (permalink)
TSF Enthusiast
 
TheOutcaste's Avatar
 
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:
Originally Posted by CarlosL View Post
Wscript.Sleep 82800000
objShell.SendKeys "%{F4}"

that statement in theory should send the F4 key after 24hrs
86400000 would be 24 hours, 82800000 is 23 hours.
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?
TheOutcaste is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-20-2009, 08:58 AM   #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.
CarlosL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-20-2009, 08:24 PM   #6 (permalink)
Tech, Networking Forums
 
Squashman's Avatar
 
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,142
OS: All of the above


Re: Using VBscript to call a window and close it.

Sounds like a job for AutoIT or AutoHotkey.
Squashman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-26-2009, 09:41 AM   #7 (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.

TheOUTCASTE:
I tried what you suggested but still not doing what i need it to do. Any Ideas?
CarlosL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-26-2009, 06:12 PM   #8 (permalink)
TSF Enthusiast
 
TheOutcaste's Avatar
 
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
Attached Images
File Type: jpg EV Dialog.JPG (13.7 KB, 1 views)
__________________
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?
TheOutcaste is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-27-2009, 08:30 AM   #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..
CarlosL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-27-2009, 11:21 PM   #10 (permalink)
TSF Enthusiast
 
TheOutcaste's Avatar
 
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?
TheOutcaste is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 08:04 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85