winapi - Autohotkey unable to kill a process -
i have facing issues svchost going out of control @ times , making system unstable. kill manually, decided write ahk script automatically everytime if starts using memory.
#noenv ; recommended performance , compatibility future autohotkey releases. #warn ; enable warnings assist detecting common errors. #singleinstance force ;-------------------------------------------------------------- ; variables ;-------------------------------------------------------------- minmemmb = 200 mincpupercentage = 50 loop { process in comobjget("winmgmts:").execquery("select idprocess, percentprocessortime, workingset win32_perfformatteddata_perfproc_process name '%svchost%'") pid = % process.idprocess cpu = % process.percentprocessortime mem = % round(process.workingset/1000000) formattime, time if (cpu > mincpupercentage or mem > minmemmb) { process, close, %pid% sleep, 2000 if errorlevel = %pid% fileappend, ( killed, %pid% , %cpu% , %mem%, %time% `r`n ), log.csv else fileappend, ( failed, %pid% , %cpu% , %mem%, %time% `r`n ), log.csv } }
my code works fine in identifying when svchost has exceeded accepted amount of memory should take. fails in killing it. log full of entries this:
failed 624 0 1036 11:15 pm wednesday may 13 2015 failed 7408 68 65 12:36 thursday may 14 2015 failed 7408 92 121 12:37 thursday may 14 2015 failed 7408 80 142 12:39 thursday may 14 2015 failed 7408 55 176 12:39 thursday may 14 2015 failed 7408 99 149 12:46 thursday may 14 2015 failed 7408 80 150 12:53 thursday may 14 2015
can me in this? should use run + taskkill instead? or there wmi command can use?
thanks.
killing svchost.exe (service host process) bad idea. instance of svchost takes care of multiple services , if kill services run under stop.
should rather try find out service causing system become unstable, find out program service part of , update or uninstall program... or in worst case stop service.
disable service keep starting automatically when windows does.
i recommend process explorer sysinternals. hover on svchost process , tooltip show services hosts.
to disable or stop service go here: win+r -> services.msc -> enter
Comments
Post a Comment