Windows
小功能
隐藏桌面快捷方式小箭头
- 下面方法,
win7
,win10
,win11
测试可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
bool ToggleShortcutArrow(bool hide) { HKEY hKey; DWORD value; LONG result; // 1. 处理 Shell Icons 设置(传统方法) if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer" "\\Shell Icons"), 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) { if (hide) { // 隐藏:设置29号图标为空 TCHAR empty[] = TEXT(""); RegSetValueEx(hKey, TEXT("29"), 0, REG_SZ, (LPBYTE)empty, sizeof(empty)); } else { // 显示:恢复默认值(删除我们的设置) RegDeleteValue(hKey, TEXT("29")); } RegCloseKey(hKey); } // 2. 修改 Explorer 设置(主要方法) if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer"), 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) { if (hide) { // 隐藏快捷方式箭头 value = 0; RegSetValueEx(hKey, TEXT("ShowInfoTip"), 0, REG_DWORD, (BYTE*)&value, sizeof(value)); // 清除链接覆盖图标 BYTE emptyBinary = 0; RegSetValueEx(hKey, TEXT("Link"), 0, REG_BINARY, &emptyBinary, 0); } else { // 显示快捷方式箭头(恢复默认) RegDeleteValue(hKey, TEXT("ShowInfoTip")); RegDeleteValue(hKey, TEXT("Link")); } // Windows 10/11 专用设置 if (IsWindows10OrLater0()) { value = hide ? 0 : 1; // 1=启用自动隐藏托盘 RegSetValueEx(hKey, TEXT("EnableAutoTray"), 0, REG_DWORD, (BYTE*)&value, sizeof(value)); } RegCloseKey(hKey); } // ===== 3. 关键修复:处理 lnkfile 设置 ===== if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"lnkfile", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) { if (hide) { // 删除 IsShortcut 值以隐藏箭头 RegDeleteValue(hKey, L"IsShortcut"); } else { // 恢复 IsShortcut 值 TCHAR empty[] = TEXT(""); RegSetValueEx(hKey, L"IsShortcut", 0, REG_SZ, (LPBYTE)empty, sizeof(empty)); } RegCloseKey(hKey); } SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)TEXT("Shell Icons"), SMTO_ABORTIFHUNG, 5000, NULL); RestartExplorer(); return true; } |
控制桌面图标的显示或隐藏
- 下面方法,
win7
,win10
,win11
测试可以 Windows7
另外处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
BOOL EnableDeskIco(EnDeskIco enDeskico, BOOL show) { BOOL hide = !show; LSTATUS result = ERROR_SUCCESS; std::wstring strCLSID = DeskicoCLSID[enDeskico]; if (IsWindows7OrGreater() && !IsWindows8OrGreater()) { const wchar_t* regPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIc" L"ons\\ClassicStartMenu"; const wchar_t* regPath1 = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIc" L"ons\\NewStartPanel"; if (enDeskico == PERSONAL_FOLDER) { DWORD value = hide ? 0 : 1; result = RegSetKeyValue( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"HideIcons", REG_DWORD, &value, sizeof(value)); RestartExplorer(); return result == ERROR_SUCCESS; } result = SHSetValue(HKEY_CURRENT_USER, regPath, strCLSID.c_str(), REG_DWORD, &hide, sizeof(DWORD)); result = SHSetValue(HKEY_CURRENT_USER, regPath1, strCLSID.c_str(), REG_DWORD, &hide, sizeof(DWORD)); RestartExplorer(); return result; } else if (IsWindows8OrGreater()) { HKEY hKey; const wchar_t* regPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIc" L"ons\\NewStartPanel"; result = SHSetValue(HKEY_CURRENT_USER, regPath, strCLSID.c_str(), REG_DWORD, &hide, sizeof(DWORD)); if (result != ERROR_SUCCESS) { return FALSE; } SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, NULL, NULL); return TRUE; } } |
Windows11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
enum EnDeskIco { DESK_RECYCLE_BIN, DESK_NETWORK, DESK_COMPUTER, DESK_DOCUMENT, DESK_CONTROL_PANEL, DESK_ONEDRIVE, }; std::map<int, std::wstring> DeskicoCLSID = { {DESK_DOCUMENT, L"{59031a47-3f72-44a7-89c5-5595fe6b30ee}"}, {DESK_COMPUTER, L"{20D04FE0-3AEA-1069-A2D8-08002B30309D}"}, {DESK_NETWORK, L"{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}"}, {DESK_RECYCLE_BIN, L"{645FF040-5081-101B-9F08-00AA002F954E}"}, {DESK_CONTROL_PANEL, L"{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}"}, {DESK_ONEDRIVE, L"{018D5C66-4533-4307-9B53-224DE2ED1FE6}"}, }; BOOL EnableDeskIco(EnDeskIco enDeskico, BOOL show) { std::wstring strCLSID = DeskicoCLSID[enDeskico]; const wchar_t* regPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcon" L"s\\NewStartPanel"; BOOL hide = !show; LSTATUS result = SHSetValue(HKEY_CURRENT_USER, regPath, strCLSID.c_str(), REG_DWORD, &hide, sizeof(DWORD)); if (result != ERROR_SUCCESS) { std::wcout << L"设置HideDesktopIcons失败" << result << std::endl; return FALSE; } SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, NULL, NULL); return TRUE; } |
控制UAC
- 需要重启电脑
- 下面方法,
win7
,win10
,win11
测试可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
BOOL EnAbleUAC(BOOL enable) { const wchar_t* regPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; BOOL value = enable; // 0表示禁用UAC LSTATUS result = SHSetValue(HKEY_LOCAL_MACHINE, regPath, L"EnableLUA", REG_DWORD, &value, sizeof(DWORD)); if (result != ERROR_SUCCESS) { std::wcout << L"设置UAC失败" << result << std::endl; return FALSE; } return TRUE; } |
控制任务栏搜索按钮
- 概述
- 任务栏搜索框集成应该是
Windows10
之后的功能 Windows7
的搜索,是在explorer
里面Windows8
的搜索,好像是全屏的,不在任务栏这里
- 任务栏搜索框集成应该是
- 选项
0
:禁用1
:启用并显示为搜索图标按钮2
:启用并显示为搜索框
- 下面方法,
win10
,win11
测试可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
enum class search_mode : int { mode_disable = 0, mode_icon, mode_search_box, }; bool DisableTaskbarSearch(search_mode mode) { HKEY hKey; LONG result; //DWORD value = static_cast<int>(mode) ? 0 : 1; // 0=禁用, 1=启用 // Windows 10/11 专用设置 if (IsWindows10OrLater0()) { // 主搜索框设置 result = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Search", 0, KEY_WRITE, &hKey); if (result == ERROR_SUCCESS) { // 搜索框显示模式 (0=隐藏, 1=显示图标, 2=显示搜索框) DWORD tmp_mode = static_cast<DWORD>(mode); RegSetValueExW(hKey, L"SearchboxTaskbarMode", 0, REG_DWORD, (BYTE*)&tmp_mode, sizeof(tmp_mode)); RegCloseKey(hKey); } // Cortana 集成设置 result = RegOpenKeyExW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", 0, KEY_WRITE, &hKey); if (result == ERROR_SUCCESS) { // 禁用Cortana按钮 DWORD disableCortana = (static_cast<int>(mode) != 0) ? 1 : 0; RegSetValueExW(hKey, L"ShowCortanaButton", 0, REG_DWORD, (BYTE*)&disableCortana, sizeof(disableCortana)); RegCloseKey(hKey); } } // 通用设置 (所有版本) result = RegOpenKeyExW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_WRITE, &hKey); if (result != ERROR_SUCCESS) { // 如果策略项不存在则创建 RegCreateKeyExW( HKEY_CURRENT_USER, L"Software\\Policies\\Microsoft\\Windows\\Explorer", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); } if (result == ERROR_SUCCESS || hKey) { // 禁用搜索按钮和框 DWORD disableButton = (static_cast<int>(mode) != 0) ? 1 : 0; RegSetValueExW(hKey, L"NoSearchBox", 0, REG_DWORD, (BYTE*)&disableButton, sizeof(disableButton)); RegSetValueExW(hKey, L"NoSearchButton", 0, REG_DWORD, (BYTE*)&disableButton, sizeof(disableButton)); RegCloseKey(hKey); } // 通知资源管理器设置已更改 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Policy", SMTO_ABORTIFHUNG, 1000, NULL); // 重启资源管理器使更改生效 //Sleep(1000); //RestartExplorer(); return true; } |
控制任务栏兴趣与咨询(小组件)
- 概述
- 是
Windows10
之后的功能 Windows10
叫做兴趣与咨询,Windows11
叫做小组件
- 是
- 下面的方法,
win10
可以,win11
没效果- 选项如下:
0
:显示图标和文本1
:仅显示图标(小图标)2
:关闭不显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
bool DisableInterestFeature(bool enable) { HKEY hKey; RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Feeds", 0, KEY_WRITE, &hKey); DWORD value = enable ? 1 : 0; // 0=禁用,1=启用 RegSetValueEx(hKey, L"ShellFeedsTaskbarViewMode", 0, REG_DWORD, (BYTE*)&value, sizeof(value)); RegCloseKey(hKey); // 刷新系统设置 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Policy", SMTO_ABORTIFHUNG, 1000, NULL); return true; } |
- 下面的方法,
win11
经验证是可以的- 选项:
0
:隐藏1
:显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
bool DisableInterestFeatureWin11(bool enable) { HKEY hKey; LPCWSTR subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; LPCWSTR valueName = L"TaskbarDa"; DWORD valueData = enable ? 1 : 0; LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (result != ERROR_SUCCESS) { return false; } result = RegSetValueExW(hKey, valueName, 0, REG_DWORD, (const BYTE*)&valueData, sizeof(valueData)); RegCloseKey(hKey); if (result != ERROR_SUCCESS) { return false; } return true; } |
- 综合
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
bool DisableInterestFeatureNewTest(bool enable) { if (IsWindows11OrLater0()) { HKEY hKey; LPCWSTR subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; LPCWSTR valueName = L"TaskbarDa"; DWORD valueData = enable ? 1 : 0; LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (result != ERROR_SUCCESS) { return false; } result = RegSetValueExW(hKey, valueName, 0, REG_DWORD, (const BYTE*)&valueData, sizeof(valueData)); RegCloseKey(hKey); if (result != ERROR_SUCCESS) { return false; } return true; } else if (IsWindows10OrLater0()) { return DisableInterestFeature(enable); } return false; } |
控制任务栏搜索中的广告
- 下面方法,
win10
,win11
测试可以 - 选项
true
:显示false
:不显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
bool DisableTaskbarSearchDynamicContent(bool enable) { if (IsWindows10OrLater0()) { HKEY hKey; LONG result; result = RegOpenKeyExW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Feeds\\DSB", 0, KEY_WRITE, &hKey); if (result != ERROR_SUCCESS) { DWORD disposition = 0; RegCreateKeyExW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Feeds\\DSB", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &disposition); } DWORD tmp = enable ? 1 : 0; RegSetValueExW(hKey, L"ShowDynamicContent", 0, REG_DWORD, (BYTE*)&tmp, sizeof(tmp)); RegCloseKey(hKey); result = RegOpenKeyExW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\SearchSettings", 0, KEY_WRITE, &hKey); if (result != ERROR_SUCCESS) { return false; } RegSetValueExW(hKey, L"IsDynamicSearchBoxEnabled", 0, REG_DWORD, (BYTE*)&tmp, sizeof(tmp)); RestartExplorer(); return true; } return false; } |
显示所有隐藏文件
- 下面方法,
win7
,win10
,win11
测试都可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
bool show_hidden_files(bool show) { HKEY hKey; LPCWSTR subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (result != ERROR_SUCCESS) { return false; } LPCWSTR valueName = L"Hidden"; DWORD valueData = show ? 1 : 0; result = RegSetValueExW(hKey, valueName, 0, REG_DWORD, (const BYTE*)&valueData, sizeof(valueData)); if (result != ERROR_SUCCESS) { RegCloseKey(hKey); return false; } if (IsWindows10OrLater0()) { SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); } else { SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Policy", SMTO_ABORTIFHUNG, 5000, nullptr); } HWND hwnd = nullptr; while ((hwnd = FindWindowExW(nullptr, hwnd, L"CabinetWClass", nullptr)) != nullptr) { PostMessageW(hwnd, WM_COMMAND, 0xA220, 0); // 发送刷新命令 } return true; } |
超级显示所有隐藏文件
- 在显示隐藏文件的基础上,还显示隐藏的系统文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
bool suppershow_hidden_files(bool show) { HKEY hKey; LPCWSTR subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (result != ERROR_SUCCESS) { return false; } LPCWSTR valueName = L"Hidden"; DWORD valueData = show ? 1 : 0; result = RegSetValueExW(hKey, valueName, 0, REG_DWORD, (const BYTE*)&valueData, sizeof(valueData)); if (result != ERROR_SUCCESS) { RegCloseKey(hKey); return false; } valueName = L"ShowSuperHidden"; result = RegSetValueExW(hKey, valueName, 0, REG_DWORD, (const BYTE*)&valueData, sizeof(valueData)); if (result != ERROR_SUCCESS) { return false; } if (IsWindows10OrLater0()) { SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); } else { SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Policy", SMTO_ABORTIFHUNG, 5000, nullptr); } HWND hwnd = nullptr; while ((hwnd = FindWindowExW(nullptr, hwnd, L"CabinetWClass", nullptr)) != nullptr) { PostMessageW(hwnd, WM_COMMAND, 0xA220, 0); } return true; } |
显示文件扩展名
- 下面方法,
win10
,win11
测试都可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
bool show_all_files_ext(bool show) { HKEY hKey; LPCWSTR subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (result != ERROR_SUCCESS) { return false; } LPCWSTR valueName = L"HideFileExt"; DWORD valueData = show ? 0 : 1; result = RegSetValueExW(hKey, valueName, 0, REG_DWORD, (const BYTE*)&valueData, sizeof(valueData)); if (result != ERROR_SUCCESS) { RegCloseKey(hKey); return false; } if (IsWindows10OrLater0()) { SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); } else { SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Policy", SMTO_ABORTIFHUNG, 5000, nullptr); } HWND hwnd = nullptr; while ((hwnd = FindWindowExW(nullptr, hwnd, L"CabinetWClass", nullptr)) != nullptr) { PostMessageW(hwnd, WM_COMMAND, 0xA220, 0); } return true; } |
显示秒数
win10
,win11
测试可行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
bool show_second_in_systemclock(bool show) { HKEY hKey; LPCWSTR subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (result != ERROR_SUCCESS) { return false; } LPCWSTR valueName = L"ShowSecondsInSystemClock"; DWORD valueData = show ? 1 : 0; result = RegSetValueExW(hKey, valueName, 0, REG_DWORD, (const BYTE*)&valueData, sizeof(valueData)); if (result != ERROR_SUCCESS) { RegCloseKey(hKey); return false; } RestartExplorer(); return true; } |
win11右键菜单修改为win10形式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
bool RestoreWin10ContextMenu(bool restore) { if (!IsWindows11OrLater0()) { return false; } HKEY hKey; LONG result; const wchar_t* clsidPath = L"Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}"; if (restore) { result = RegCreateKeyExW( HKEY_CURRENT_USER, clsidPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_WOW64_64KEY, NULL, &hKey, NULL); if (result != ERROR_SUCCESS) { return false; } HKEY hSubKey; result = RegCreateKeyEx(hKey, L"InprocServer32", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_WOW64_64KEY, NULL, &hSubKey, NULL); if (result != ERROR_SUCCESS) { RegCloseKey(hKey); return false; } wchar_t empty[] = L""; result = RegSetValueEx(hSubKey, L"", 0, REG_SZ, (BYTE*)empty, sizeof(empty)); if (result != ERROR_SUCCESS) { RegCloseKey(hSubKey); RegCloseKey(hKey); return false; } RegCloseKey(hSubKey); RegCloseKey(hKey); } else { HKEY hKey; result = RegOpenKeyExW(HKEY_CURRENT_USER, clsidPath, 0, KEY_WRITE | KEY_WOW64_64KEY, &hKey); if (result != ERROR_SUCCESS) { return false; } result = RegDeleteTreeW(hKey, L"InprocServer32"); if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { return false; } } RestartExplorer(); return true; } |
辅助函数
是否win10
以后
win11
的版本是10.0.22000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
bool IsWindows10OrLater0() { using RtlGetVersionPtr = NTSTATUS(WINAPI*)(PRTL_OSVERSIONINFOW); auto RtlGetVersion = reinterpret_cast<RtlGetVersionPtr>( GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion")); if (!RtlGetVersion) return false; RTL_OSVERSIONINFOW info = {sizeof(info)}; if (SUCCEEDED(RtlGetVersion(&info))) { return (info.dwMajorVersion > 10) || (info.dwMajorVersion == 10 && info.dwMinorVersion >= 0); } return false; } |
是否win11
以后
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
bool IsWindows11OrLater0() { using RtlGetVersionPtr = NTSTATUS(WINAPI*)(PRTL_OSVERSIONINFOW); auto RtlGetVersion = reinterpret_cast<RtlGetVersionPtr>( GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion")); if (!RtlGetVersion) return false; RTL_OSVERSIONINFOW info = {sizeof(info)}; if (SUCCEEDED(RtlGetVersion(&info))) { return (info.dwMajorVersion > 10) || ((info.dwMajorVersion == 10) && (info.dwMinorVersion >= 0) && (info.dwBuildNumber >= 22000)); } return false; } |
重启Explore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
void RestartExplorer() { HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap != INVALID_HANDLE_VALUE) { PROCESSENTRY32 pe32; pe32.dwSize = sizeof(PROCESSENTRY32); if (Process32First(hProcessSnap, &pe32)) { do { if (_wcsicmp(pe32.szExeFile, L"explorer.exe") == 0) { HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID); if (hProcess) { TerminateProcess(hProcess, 0); CloseHandle(hProcess); } } } while (Process32Next(hProcessSnap, &pe32)); } CloseHandle(hProcessSnap); } } |
声明:本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 包管理器:各平台安装卸载相关记述09/17
- ♥ WinDbg命令标记、命令07/11
- ♥ 关于多字节和宽字节一11/10
- ♥ Windows IOCP07/22
- ♥ Windows 核心编程 _ 进程五06/30
- ♥ Windows 核心编程 _ 内核对象二06/07