• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Scripting

Shambler

Supreme [H]ardness
Joined
Aug 17, 2005
Messages
6,419
Starting to mess around with scripting and I need a bit of help.

I would like to combine the following two scripts:

http://gallery.technet.microsoft.com/scriptcenter/en-us/52974cee-5de4-451b-9a21-b178c04d9a0b

and

http://gallery.technet.microsoft.com/scriptcenter/en-us/fac36513-672c-476f-a446-9032e41e1d1a

They are almost identical, which is nice. However, I am very new to scripting and I'm not sure how to tackle this? Do I declare everything up top or per loop. And probably the hardest part, how do I have the processor loop run, then wait 5 seconds or whatever, and during that 5 seconds have the mem loop run?

Shoot, I don't even need step by step instructions, if someone could just combine them, I could look at the result and start messing around.

Gracias
 
can't you just have each loop run in succession (serial), then sleep afterward?

ie.
Code:
define variables here

do
    do
      loop for cpu stuff here
    loop
    do
      loop for mem stuff here
    loop
    sleep x seconds
loop

that's what you want, right?
 
I am able to get either the Mem or Proc loop to run just fine. However, it will not run whatever is listed second. Below is the script I am screwing around with. Mem is first, Proc is second.

strAnswer = InputBox("Please enter a machine name:", _
"Machine name")
strcomputer = stranswer
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
Set objProcessor = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSet
intThresholdViolations = 0
Set objMemory = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet
objRefresher.Refresh

Do
For Each intAvailableBytes in objMemory
If intAvailableBytes.AvailableMBytes < 600 Then
Wscript.Echo "Available memory has fallen below 4 megabytes."
Wscript.Echo "Time " & Now()
End If
Next
objRefresher.Refresh
Loop

Do
For Each intProcessorUse in objProcessor
If intProcessorUse.PercentProcessorTime > 90 Then
intThresholdViolations = intThresholdViolations + 1
If intThresholdViolations = 10 Then
intThresholdViolations = 0
Wscript.Echo "Processor usage on machine " & strcomputer &" threshold exceeded."
Wscript.Echo "Time " & Now()
End If
Else
intThresholdViolations = 0
End If
Next
Wscript.Sleep 6000
objRefresher.Refresh
Loop
 
Your Do Loop doesn't have a conditional statement to end it, so it'll run the first one indefinitely.
 
Back
Top