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,020 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now