현재 "Software \ Microsoft \ Windows \ CurrentVersion \ Run"에서 하위 키를 삭제하려고합니다. 문제는 내 오류 코드가 유일하고 그것에 대한 유일한 질문이 답변되지 않은 모든 가능한 해결책을 시도해 보았습니다 : how to remove program from startup list using c++. Windows x64에서 Visual Studio 10을 사용하고 있습니다. programm은 Win32 응용 프로그램입니다.VS C++ 하위 키 삭제가 작동하지 않습니다! 오류 코드 0
와만든 키
여기BOOL registerForLocalStartup(PCWSTR regName, PCWSTR pathToExe, PCWSTR args)
{
HKEY hKey = NULL;
LONG lResult = 0;
BOOL fSuccess = TRUE;
DWORD dwSize;
const size_t count = MAX_PATH * 2;
wchar_t szValue[count] = {};
wcscpy_s(szValue, count, L"\"");
wcscat_s(szValue, count, pathToExe);
wcscat_s(szValue, count, L"\" ");
if (args != NULL)
{
// caller should make sure "args" is quoted if any single argument has a space
// e.g. (L"-name \"Mark Voidale\"");
wcscat_s(szValue, count, args);
}
// For admin HKEY_LOCAL_MACHINE
lResult = RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, (KEY_WRITE | KEY_READ), NULL, &hKey, NULL);
fSuccess = (lResult == 0);
if (fSuccess)
{
dwSize = (wcslen(szValue) + 1) * 2;
lResult = RegSetValueExW(hKey, regName, 0, REG_SZ, (BYTE*)szValue, dwSize);
fSuccess = (lResult == 0);
}
if (hKey != NULL)
{
RegCloseKey(hKey);
hKey = NULL;
}
return fSuccess;
}
내 코드 :
bool DeleteValueKey(HKEY hKeyRoot, std::wstring Subkey, std::wstring ValueKey)
{
HKEY hKey = NULL;
bool bReturn = false;
long result = RegOpenKeyEx(hKeyRoot, Subkey.c_str(), 0, KEY_READ | KEY_WRITE | KEY_WOW64_32KEY, &hKey);
wcout << "Result of RegOpenKeyEx: " << result << endl;
if (result == ERROR_SUCCESS)
{
long result2 = RegDeleteKeyEx(hKey, ValueKey.c_str(), KEY_WOW64_32KEY, 0);
wcout << "Result of RegDeleteKeyEx: " << result2 << endl;
if (result2 == ERROR_SUCCESS)
{
bReturn = true;
}
}
if (hKey != NULL) { RegCloseKey(hKey); }
return bReturn;
}
그리고 이것이 내가 전화 뭘하려 :
bool result = DeleteValueKey(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", L"test1");
if (result)
{
wcout << "SUCCESS" << endl;
}
else
{
wcout << "FAILURE: "<< GetLastError() << endl;
}*/
출력 :
Result of RegOpenKeyEx: 0
Result of RegDeleteKeyEx: 2
FAILURE: 0
누구에게 아이디어가 있습니까? 나는
왜 레지스트리 함수의 반환 값을 검사하여 실제 오류인지 확인하지 마십시오. 코드가이 중요한 정보를 삭제합니다. –
프로그램이 32 비트 또는 64 비트입니까? 귀하의 Windows 32 비트 또는 64 비트입니까? 어떤 오류 코드가 나옵니까? ':: GetLastError()'는 무엇을 반환합니까? –
Windows x64를 사용하고 응용 프로그램이 x32입니다. 내가 얻는 오류 코드는 0입니다. – Qubasa