|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBScript - Recognizing a running program and then waiting ...
Hey guys,
I was wondering if anyone could help me with another problem I ran into. Simply put, How can I check to see if a program is currently running, and if so, cause my script to wait until it stops ?? If I am causing the disk cleanup to run in my script, I need to make my script wait until it is finished before continuing with another program. I tried the WScript.Sleep(), but it isn't working as needed. Any thoughts and idea's are very welcome and appreciated. Thanks, Hangman. ![]() |
|
#2
|
||||||||
|
||||||||
|
There are two common methods of monitoring programs in WSH. Since Disk Cleanup runs in a window, you can use the WshShell object's AppActivate method to effectively see whether the window is open. You'll need to know the window's title screen and then attempt to activate it. The method returns true if the window can be activated and false if it can't. You can then create a simple loop to pause your script while the window is open.
vb Code:
vb Code:
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! Last edited by Nilpo : July 29th, 2008 at 02:09 AM. |
|
#3
|
|||||
|
|||||
|
I see now that you are launching the Disk Cleanup Wizard from your script. There is a much easier way to accomplish this.
vb Code:
The Disk Cleanup Wizard can be fully automated from the command line. For more information, see the following Knowledgebase Article. How to Automate the Disk Cleanup Tool in Windows XP Lots of info here. Hope this helps! Last edited by Nilpo : July 29th, 2008 at 02:24 AM. Reason: Added KB Link |
|
#4
|
|||||
|
|||||
|
Quote:
Yes, here is my code: Code:
Function ExecuteCleanupUtility() 'Run the Windows Disk Cleanup utility objWshShl.Run "C:\WINDOWS\SYSTEM32\cleanmgr /sagerun:64" WScript.Sleep(300000) End Function Although I am using the /sagerun:# function rather than the /d function you mentioned below, but it works superbly. Here's what I changed: Code:
Function ExecuteCleanupUtility() 'Run the Windows Disk Cleanup utility objWshShl.Run "C:\WINDOWS\SYSTEM32\cleanmgr /sagerun:64",, True End Function Quote:
When I first set this up, I was looking at that paper, good stuff there, thanks. I am however, really interested in knowing where I can find all those little tidbits of information you have, like the following you mentioned: Quote:
I haven't been able to find a description of the WshShell object's Run method that describes this. Of course I haven't looked too deeply yet since reading your post. Thank you though, this looks & works much better now. |
|
#5
|
||||
|
||||
|
I'm glad that worked out for you!
I was hoping you'd be using sagerun but it was too much info to get into in one post.Most of my "tidbits" come from experience, tbh. However, the MSDN is a great place to find them if you're not afraid to do some digging. Here's a link to the MSDN section that describes the Run method and its parameters. |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > VBScript - Recognizing a running program and then waiting ... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|