Description:
This script file handles the high cpu usage by change the windows setting to balanced mode and returns the process which has more than 20 mb.
Note:
Run as Local System User
import os
from subprocess import PIPE,Popen
import ctypes
import time
start=time.time()
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
with disable_file_system_redirection():
load=os.popen("wmic cpu get loadpercentage").read()
percent=int(load.split()[1])
print "Load Percantage %s percent"%percent
if percent >90:
print "System has been Changed to balanced setting"
process=Popen('''powercfg /changename 381b4222-f694-41f0-9685-ff5bb260df2e "Customized Balanced"''',stdout=PIPE,stderr=PIPE)
r,e=process.communicate()
if e:
print e
else:
print r
print "Process list which using more than 20MB Kindly Close this process and Restart the system"
process1=Popen('''powershell.exe Get-Process | Where-Object {$_.WorkingSet -gt 20000000}''',stdout=PIPE,stderr=PIPE)
r1,e1=process1.communicate()
if e1:
print e1
else:
print r1
Comments