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,043 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

710 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