Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-16
7
Medium Priority
?
1,057 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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