我正在尝试从DisableCMD
编辑C++
,但是每当我尝试调用这些函数时,我都会得到ERROR_SUCCESS
,但是转到else语句,但仍然没有编辑我的注册表值。我还遇到keys/registries
名称的麻烦。我不知道他们是否想要完整路径。
HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\DisableCMD
-完整路径(某些人的计算机上可能没有此路径,我手动添加了我的它,它可以禁用CMD)
我查看了存在此问题的其他问题,但我仍然感到困惑。
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <Windows.h>
#include <cstdio>
int main()
{
BYTE lpData[32];
CONST BYTE lpDataNew = 2;
DWORD lpType = { REG_DWORD };
DWORD lpcbData = {sizeof(lpData)};
HKEY hKey = 0;
char regPath[64] = "\\Software\\Policies\\Microsoft\\Windows\\System";
char lpValueName[32] = "DisableCMD";
long regOKExA = RegOpenKeyExA(HKEY_CURRENT_USER, regPath, 0, KEY_ALL_ACCESS, &hKey);
if (regOKExA == ERROR_SUCCESS)
{
std::cout << "Successfully executed RegOpevnKeyExA\n";
}
else
{
std::cout << "An error has occurred while executing RegOpenKeyExA. Error code: " << GetLastError();
getchar();
return EXIT_FAILURE;
}
long regQVExA = RegQueryValueExA(hKey, lpValueName, NULL, &lpType, (LPBYTE)lpData, &lpcbData);
if (regQVExA == ERROR_SUCCESS)
{
std::cout << "Successfully executed RegQueryValueExA\n";
}
else
{
std::cout << "An error has occurred while executing RegQueryValueExA. Error code: " << GetLastError();
getchar();
return EXIT_FAILURE;
}
long regSVExA = RegSetValueExA(hKey, lpValueName, 0, REG_DWORD, &lpDataNew, lpcbData);
if (regSVExA == ERROR_SUCCESS)
{
std::cout << "Successfully executed RegSetValueExA\n";
}
else
{
std::cout << "An error has occurred while executing RegSetValueExA. Error code: " << GetLastError();
getchar();
return EXIT_FAILURE;
}
RegCloseKey(hKey);
// Close handle hReceive
return 0;
}
我希望他们说Successfully executed...
,但是即使返回成功,它也会一直返回An error has occurred while executing...
。