现象

CPU和磁盘占用率总是莫名其妙地拔高,一打开任务管理器(Task Manager),又马上降下去。

  任务管理器开着,没过一会儿会被自动关掉,系统占用率又会继续飙升。

思路

  既然打开任务管理器可以让系统资源免于被占用,那就使其保持运行状态即可。

  任务管理器所在路径:C:\Windows\System32

  任务管理器程序名称:Taskmgr.exe

方法

C代码,将生成的可执行程序放置于开机启动文件夹

  代码中的变量oldPath用户需(可)根据实际情况需改,变量saveFileName可根据实际情况需改

代码

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <windows.h>

int main()
{
	ShowWindow(GetConsoleWindow(),SW_HIDE);
	FILE *fp;
	char *oldPath = "C:/Users/Public/Documents/";
	char path[62] = {};
	strcpy(path, oldPath);
	char *saveFileName = "keep_task_manager_open.log";
	strcat(path, saveFileName);
	// printf("%s\n", path);
	fp = freopen(path, "a+", stdout);
	
    time_t tmpcal_ptr;
	struct tm *tmp_ptr = NULL;
	
	time(&tmpcal_ptr);
    // tmpcal_ptr = time(NULL);	// Both methods shall be effective.
	
	tmp_ptr = localtime(&tmpcal_ptr);
	printf ("%skeep_task_manager_open.exe Starts: %d-%02d-%02d ", _pgmptr, (1900+tmp_ptr->tm_year), (1+tmp_ptr->tm_mon), tmp_ptr->tm_mday);
	printf("%02d:%02d:%02d\n", tmp_ptr->tm_hour, tmp_ptr->tm_min, tmp_ptr->tm_sec);
	fclose(fp);
	
	//system("taskkill /F /IM AlibabaprotectUI.exe"); // Can be commented if not used. 
	//system("taskkill /F /IM FoxitCapture.exe"); // Can be commented if not used. 
	
	while(1)
	{
		system("taskmgr.exe");
		//printf("Task Manager Created.");
		//Sleep(5 * 1000);
		//system("taskkill /F /IM taskmgr.exe");
		//printf("Task Manager Killed.");
	}
	return 0;
}

开机启动文件夹

Win+R组合键打开Run窗口,如图1所示。


zabbix 得到cpu空闲率如何计算使用率 空闲时cpu使用率很高_2d


图 1


shell:startup,如图2所示;回车即可进入开机启动文件夹,如图3所示。


zabbix 得到cpu空闲率如何计算使用率 空闲时cpu使用率很高_#include_02


图 2



zabbix 得到cpu空闲率如何计算使用率 空闲时cpu使用率很高_任务管理器_03


图 3


keep_task_manager_open.exe(程序名可自定义)放置在开机启动文件夹,如图4所示,即可保证每次开机或重启后,程序自动在后台启动运行。


zabbix 得到cpu空闲率如何计算使用率 空闲时cpu使用率很高_#include_04


图 4


5所示,为程序在后台运行截图。


zabbix 得到cpu空闲率如何计算使用率 空闲时cpu使用率很高_#include_05


图 5


oldPath所指定路径生成一个由变量saveFileName指定名称的.log文件,并写入程序所在路径、程序名以及启动时间,如果文件已存在则向文件末尾添加相关内容,如图6与图7所示。


zabbix 得到cpu空闲率如何计算使用率 空闲时cpu使用率很高_任务管理器_06


图 6



zabbix 得到cpu空闲率如何计算使用率 空闲时cpu使用率很高_2d_07


图 7



注意事项

直接运行程序,如果导致任务管理器无法最小化、光标一直在转圈等问题,可先将程序放置在开启启动文件夹中,然后重启电脑,即可解决问题。

  若有其他与本程序有关的问题,可留言。