Solved

In VBScript how can I trigger an action if a process has been idle for 2 minutes?

Posted on 2011-03-16
7
1,034 Views
Last Modified: 2012-05-11
I need to be able to monitor cpu utilization on a process (setup.exe) so that I can reboot the system if the "sngProcessTime is <0.5" for 2 minutes.  The script below calls a Reboot sub if the "sngProcessTime is <0.5" at the interval in the outer For-Next loop.  

The reason for this is we have a video driver update (setup.exe) that tends to just sit there even after the installation is complete.

How can this be modified to perform the action: Call Reboot if "sngProcessTime is <0.5 for a period of 2 minutes"?

Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Setup.exe'")
For i = 1 to 10
  For Each objProcess In colProcesses
     sngProcessTime = ( CSng(objProcess.KernelModeTime) + _
	                  CSng(objProcess.UserModeTime)) / 10000000
  Next 
wscript.sleep 30000
       If sngProcessTime < 0.5 Then
	     Call Reboot
       End If
Next	

Open in new window


Thank you.
0
Comment
Question by:tneubauertocg
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:prashanthd
ID: 35154196
Do you want the script to keep monitor continuously, or only once?
0
 

Author Comment

by:tneubauertocg
ID: 35156553
I need it to monitor the Setup.exe process continuously (during script execution) until it has been idle for 2 minues - then call the reboot sub.
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 35157159
Try the following code...

regards
Prashanth
status=False
ststusnew=False

Do While status=False
    
    Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Setup.exe'")
    For Each objProcess In colProcesses
        sngProcessTime = ( CSng(objProcess.KernelModeTime) + _
        CSng(objProcess.UserModeTime)) / 10000000
        'WScript.Echo sngProcessTime & " - 1 "
    Next
    ststusnew=False
    If sngProcessTime < 0.5 Then
        timestr=DateAdd("n",2,Now)
        'WScript.Echo "in next"
        Do While Now <= timestr
            
            Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Setup.exe'")
            For Each objProcess In colProcesses
                sngProcessTime = ( CSng(objProcess.KernelModeTime) + _
                CSng(objProcess.UserModeTime)) / 10000000
                'WScript.Echo sngProcessTime & "in 2"
            Next
            
            If sngProcessTime > 0.5 Then
                WScript.Echo ">" & sngProcessTime
                ststusnew=True
                Exit Do
            End If	
        Loop
        If ststusnew=False Then
            Call Reboot
            status=True
        End If
    End If   
Loop

Open in new window

0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Closing Comment

by:tneubauertocg
ID: 35157443
Prashanth - this is brilliant, it works like a charm!  Thank you very much!
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35157965
Glad it worked!! Thanks for the points..
0
 

Author Comment

by:tneubauertocg
ID: 35198841
I did find one thing missing that makes it bullet proof.  It was retaining the sngProcessTime value so I had to insert "sngProcessTime = 0" right before the "For-Next" loop on line 7. So now it looks like:

Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name =" & strProcessName)
sngProcessTime = 0
    For Each objProcess In colProcesses
        sngProcessTime = ( CSng(objProcess.KernelModeTime) + _
        CSng(objProcess.UserModeTime)) / 10000000
        'WScript.Echo sngProcessTime & " - 1 "
    Next
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question