电源选项.lnk
C:\Windows\System32\powercfg.cpl
蓝牙.lnk
C:\Windows\System32\bthprops.cpl
清理图标缓存.bat
@echo off
taskkill /f /im explorer.exe
DEL /F /Q "%userprofile%\AppData\Local\IconCache.db"
start explorer.exe
关闭显示器.bat
powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int PostMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::PostMessage(-1,0x0112,0xF170,2)
简单修复HOSTS文件.cpp
#include <iostream>
#include <fstream>
#include <string>
#include<ctime>
using namespace std;
const int hosts_length=24;
char original_HOSTS[hosts_length][80]{"\
# Copyright (c) 1993-2009 Microsoft Corp.","\
#","\
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.","\
#","\
# This file contains the mappings of IP addresses to host names. Each","\
# entry should be kept on an individual line. The IP address should","\
# be placed in the first column followed by the corresponding host name.","\
# The IP address and the host name should be separated by at least one","\
# space.","\
#","\
# Additionally, comments (such as these) may be inserted on individual","\
# lines or following the machine name denoted by a '#' symbol.","\
#","\
# For example:","\
#","\
# 102.54.94.97 rhino.acme.com # source server","\
# 38.25.63.10 x.acme.com # x client host","\
","\
# localhost name resolution is handled within DNS itself.","\
# 127.0.0.1 localhost","\
# ::1 localhost","\
# XMind Mind-Mapper","\
0.0.0.0 xmind.net","\
0.0.0.0 www.xmind.net"
};
//struct tm {
// int tm_sec; /* 秒,范围从 0 到 59 */
// int tm_min; /* 分,范围从 0 到 59 */
// int tm_hour; /* 小时,范围从 0 到 23 */
// int tm_mday; /* 一月中的第几天,范围从 1 到 31 */
// int tm_mon; /* 月份,范围从 0 到 11 */
// int tm_year; /* 自 1900 起的年数 */
// int tm_wday; /* 一周中的第几天,范围从 0 到 6 */
// int tm_yday; /* 一年中的第几天,范围从 0 到 365 */
// int tm_isdst; /* 夏令时 */
//};
string backupTime(){
time_t rawtime;
time(&rawtime);
struct tm *info = localtime(&rawtime);
string str;
str+="_"+to_string(info->tm_year+1900);
str+="_"+to_string(info->tm_mon+1);
str+="_"+to_string(info->tm_mday);
str+="_"+to_string(info->tm_hour);
str+="_"+to_string(info->tm_min);
str+="_"+to_string(info->tm_sec);
return str;
}
// 修复 HOSTS 文件
void fixHostsFile() {
string hostsFilePath = "C:\\Windows\\System32\\drivers\\etc\\hosts";
string backupFilePath = "C:\\Windows\\System32\\drivers\\etc\\hosts_backup\\hosts"; // 备份文件路径
FILE *fp = fopen(hostsFilePath.c_str(),"r");
//.data()与.c_str()返回的都是const char指针
//fclose(fp);//关闭函数不影响fp指针的值
if(fp==0){//没文件,目标文件不存在
;
}
else{
fclose(fp);//写在这里更规范点,因为不知道指针值为0的位置有什么
system(("copy "+hostsFilePath+" "+backupFilePath+backupTime()).c_str());
cout << "修复前的 HOSTS文件 的备份在:" << backupFilePath << endl;
}
fp = fopen(hostsFilePath.c_str(),"w");
for(int i=0;i<hosts_length;i++){
fprintf(fp,"%s\n",original_HOSTS[i]);
}
fclose(fp);
cout << "HOSTS 文件修复完成" << endl << endl;
}
// 修复 IE 代理
void fixIEProxy() {
string registryPath = "\"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\"";
//坑: Internet Settings中间有空格,所以整体路径要用引号引起来
string proxyEnableKey = "ProxyEnable";
system(("REG ADD " + registryPath + " /v " + proxyEnableKey + " /t REG_DWORD /d 0 /f").c_str()); // 设置 ProxyEnable 值为 0,表示禁用代理
cout << "IE 代理修复完成" << endl;
}
int main() {
fixHostsFile();
fixIEProxy();
system("pause");
return 0;
}