開發工具:Visual Studio 2010
程式語言:C/C++
程式功能:讀取與修改Windows機碼,範例是關閉Windows 7錯誤回報的顯示。
//HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting
//"DontShowUI"=dword:00000001
#include <stdlib.h>
#include <Windows.h>
#include <atlconv.h>
long reg()
{
HKEY hKey;
long errorlevel = 0L;
char* reg_video_path = "Software\\Microsoft\\Windows\\Windows Error Reporting"; // Registry path
char* value_name = "DontShowUI"; // The key
DWORD dwType = 0x00000000, dwSize = 0x00000000;
DWORD data = 0x00000000;
USES_CONVERSION;
// Step 1: open key.
errorlevel = RegOpenKeyExW(HKEY_CURRENT_USER, A2W(reg_video_path), 0, KEY_ALL_ACCESS, &hKey);
if(errorlevel != ERROR_SUCCESS) return errorlevel;
// Step 2: read size. (necessary)
errorlevel = RegQueryValueEx(hKey, A2W(value_name), NULL, &dwType, NULL, &dwSize);
if(errorlevel != ERROR_SUCCESS) return errorlevel;
// Step 3: read value.
errorlevel = RegQueryValueExW(hKey, A2W(value_name), NULL, &dwType, (LPBYTE)&data, &dwSize);
if(errorlevel != ERROR_SUCCESS) return errorlevel;
// TODO: set new data.
// Step 4: set value.
errorlevel = RegSetValueExW(hKey, A2W(value_name), 0, REG_DWORD, (const BYTE*)&data, sizeof(DWORD));
if(errorlevel != ERROR_SUCCESS) return errorlevel;
// step 5: close key.
errorlevel = RegCloseKey(hKey);
if(errorlevel != ERROR_SUCCESS) return errorlevel;
return 0L;
}
Windows的版本不同,機碼名稱和值也可能不同,所以要針對作業系統的版本去寫。
沒有留言:
張貼留言