Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 28th, 2008, 10:27 AM
Hangman Hangman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 29 Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 56 m 6 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old July 29th, 2008, 02:07 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,253 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 3 m 7 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
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:
Original - vb Code
  1. Set WshShell = CreateObject("WScript.Shell")
  2.  
  3. Do While WshShell.AppActivate("Disk Cleanup")
  4.     WScript.Sleep 1000 ' Wait while window is open
  5. Loop
  6.  
  7. WScript.Echo "Disk Cleanup has completed."
Perhaps a more proper way to monitor the Disk Cleanup Wizard is to watch the cleanmgr.exe process using WMI. When done within a function, you can easily create a timer loop as before.
vb Code:
Original - vb Code
  1. Do While IsRunning
  2.     WScript.Sleep 1000
  3. Loop
  4.  
  5. WScript.Echo "Disk Cleanup has completed."
  6.  
  7. Function IsRunning
  8.     Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  9.     Set colProcesses = objWMIService.ExecQuery("Select * From Win32_Process " & _
  10.         "Where Name = 'cleanmgr.exe'")
  11.  
  12.     If colProcesses.Count > 0 Then
  13.         IsRunning = True
  14.     Else
  15.         IsRunning = False
  16.     End If
  17. End Function
Either of these methods should be effective for you.
__________________
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.

Reply With Quote
  #3  
Old July 29th, 2008, 02:20 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,253 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 3 m 7 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
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:
Original - vb Code
  1. Set WshShell = CreateObject("WScript.Shell")
  2.  
  3. WshShell.Run "cleanmgr.exe /d C:",, True
The WshShell object's Run method accepts a Boolean value as its third parameter that indicates whether the script should wait for the program to terminate before continuing. Using a value of True will effectively wait until the Wizard finishes.

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

Reply With Quote
  #4  
Old July 29th, 2008, 04:01 PM
Hangman Hangman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 29 Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 56 m 6 sec
Reputation Power: 0
Quote:
Originally Posted by Nilpo
I see now that you are launching the Disk Cleanup Wizard from your script. There is a much easier way to accomplish this.[highlight=vb]Set WshShell = CreateObject("WScript.Shell")


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:
Originally Posted by Nilpo
... 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!


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:
The WshShell object's Run method accepts a Boolean value as its third parameter that indicates whether the script should wait for the program to terminate before continuing. Using a value of True will effectively wait until the Wizard finishes.


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.

Reply With Quote
  #5  
Old July 29th, 2008, 09:45 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,253 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 3 m 7 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > VBScript - Recognizing a running program and then waiting ...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT