OEMBackground 要设置成REG_DWORD 类型
时间: 2024-01-14 22:03:25 浏览: 109
非常感谢您的指正!您是正确的,OEMBackground 的类型应该是 REG_DWORD。以下是修改后的代码:
```c
#include <windows.h>
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
{
HKEY hKey;
DWORD dwType, dwSize, dwValue;
TCHAR szValue[MAX_PATH] = {0};
TCHAR szPath[MAX_PATH] = {0};
TCHAR szDefaultPath[MAX_PATH] = _T("C:\\Windows\\System32\\oobe\\info\\backgrounds\\backgroundDefault.jpg");
DWORD dwDisposition = 0;
// 打开注册表键
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI\\Background"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) {
// 设置壁纸路径
_tcscpy_s(szPath, MAX_PATH, _T("C:\\Windows\\System32\\oobe\\info\\backgrounds\\mybackground.jpg"));
dwValue = 1;
RegSetValueEx(hKey, _T("OEMBackground"), 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
RegSetValueEx(hKey, _T("OEMBackgroundImagePath"), 0, REG_SZ, (LPBYTE)szPath, (_tcslen(szPath) + 1) * sizeof(TCHAR));
RegCloseKey(hKey);
}
// 设置默认壁纸路径
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI\\Background"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
dwSize = MAX_PATH;
if (RegQueryValueEx(hKey, _T("OEMBackgroundImagePath"), NULL, &dwType, (LPBYTE)szValue, &dwSize) == ERROR_SUCCESS) {
if (_tcslen(szValue) > 0 && _tcsicmp(szValue, szDefaultPath) != 0) {
// 如果当前壁纸不是默认壁纸,则备份当前壁纸并设置默认壁纸
_tcsncpy_s(szPath, MAX_PATH, szValue, MAX_PATH - 1);
_tcscat_s(szPath, MAX_PATH, _T(".bak"));
CopyFile(szValue, szPath, FALSE);
RegSetValueEx(hKey, _T("OEMBackgroundImagePath"), 0, REG_SZ, (LPBYTE)szDefaultPath, (_tcslen(szDefaultPath) + 1) * sizeof(TCHAR));
}
}
RegCloseKey(hKey);
}
return 0;
}
```
再次感谢您的指正,希望这次的答案能够满足您的需求。
阅读全文