Registery Keys



  • Wieso lässt sich der Reg Key nicht löschen?

    RegDeleteKey sagt:
    ERROR_ENVVAR_NOT_FOUND
    203 (0xCB)
    The system could not find the environment option that was entered.

    Aber was ist an dem Code falsch? Ich kapiers nicht.

    #include <windows>
    using namespace std;
    
    int main()
    {
    HKEY hKey ;
    string str = "Software\\test";
    long ret = RegOpenKeyEx( HKEY_CURRENT_USER, str.c_str() , 0, KEY_ALL_ACCESS , &hKey );
    cout<< ret << endl;
    
    cout<<"ret del: " << RegDeleteKey( hKey, str.c_str() ) << endl;
    cout<<GetLastError()<<endl;
    
    system("PAUSE");
    }
    


  • So müsste es funktionieren:

    #include <windows>
    using namespace std;
    
    int main()
    {
    HKEY hKey ;
    string str = "Software";
    string subkey = "test";
    long ret = RegOpenKeyEx( HKEY_CURRENT_USER, str.c_str() , 0, KEY_ALL_ACCESS , &hKey );
    cout<< ret << endl;
    
    cout<<"ret del: " << RegDeleteKey( hKey, subkey.c_str() ) << endl;
    cout<<GetLastError()<<endl;
    
    system("PAUSE");
    }
    

    oder so:

    #include <windows>
    using namespace std;
    
    int main()
    {
    string str = "Software\\test";
    
    cout<<"ret del: " << RegDeleteKey( HKEY_CURRENT_USER, str.c_str() ) << endl;
    cout<<GetLastError()<<endl;
    
    system("PAUSE");
    }
    

    Außer es gibt unterhalb des Schlüssels Software\test einen Unterschlüssel Software\test und Du willst den löschen.

    mfg Martin



  • Danke, bei HKEY_CURRENT_USER funktioniert es ohne Probleme:
    Doch mit HKEY_LOCAL_MACHINE funktioniert es nicht ...

    RegDeleteKey sagt wieder:
    ERROR_ENVVAR_NOT_FOUND
    203 (0xCB)
    The system could not find the environment option that was entered.

    Ich hab schon rum gegoogelt aber nichts scheint zu funktioniert. Diese scheiss API macht mich noch Wahnsinnig !!!! 😡

    #include <iostream>
    #include <windows>
    using namespace std;
    
    int main()
    {
    
    HKEY hKey ;
    string str = "Software";
    
    long ret = RegOpenKeyEx( HKEY_LOCAL_MACHINE, str.c_str(), 0, KEY_ALL_ACCESS , &hKey );
    	if ( ret != ERROR_SUCCESS)
    	{
    		cout<<"RegOpenKeyEx error: " << GetLastError() << "\n";
    	}
    
    string subkey = "test";
    cout<<"ret del: " << RegDeleteKey( hKey, subkey.c_str() ) << endl;
    cout<<GetLastError()<<endl;
    
    system("PAUSE");
    }
    


  • FuRegKey schrieb:

    Danke, bei HKEY_CURRENT_USER funktioniert es ohne Probleme:
    Doch mit HKEY_LOCAL_MACHINE funktioniert es nicht ...

    RegDeleteKey sagt wieder:
    ERROR_ENVVAR_NOT_FOUND
    203 (0xCB)
    The system could not find the environment option that was entered.

    Hat denn RegOpenKey keinen Fehler gemeldet? Ich würde nämlich eher auf ein Berechtigungsproblem tippen.

    mfg Martin



  • RegOpenKeyEx gibt keinen Fehler zurück. RegDeleteKey gibt den Fehlercode 203 aus.
    Und ja ich hab das Programm als Admin gestartet.

    Seltsam das dass nicht funktionieren will.



  • Keiner eine Ahnung was da falsch laufen könnte? 😞



  • Wieso <windows> und nicht <windows.h>? Wieso kein <string>?

    Ansonsten funktioniert dein Code bei mir (als Admin ausgeführt und das hier beachtet). Was gibt denn RegDeleteKey bei dir überhaupt zurück? ERROR_ENVVAR_NOT_FOUND stammt höchstwahrscheinlich von woanders her.



  • EinGast schrieb:

    Ansonsten funktioniert dein Code bei mir (als Admin ausgeführt und das hier beachtet). Was gibt denn RegDeleteKey bei dir überhaupt zurück? ERROR_ENVVAR_NOT_FOUND stammt höchstwahrscheinlich von woanders her.

    Stimmt daran habe ich nicht gedacht. 👍
    @FuRegKey, schau mal unter HKEY_LOCAL_MACHINE\Software\Wow6432Node

    mfg Martin



  • Danke jetzt funktoniert es:

    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main()
    {
    
    HKEY hKey ;
    string str = "Software";
    
    long ret = RegOpenKeyEx( HKEY_LOCAL_MACHINE, str.c_str(), 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey );
    	if ( ret != ERROR_SUCCESS)
    	{
    		cout<<"RegOpenKeyEx error: " << GetLastError() << "\n";
    	}
    
    string subkey = "test";
    ret = RegDeleteKey( hKey, subkey.c_str());
    
    	if ( ret !=  ERROR_SUCCESS)
    	{
    		cout<<"RegDeleteKey: " << ret << "\n";
    		cout<<"Error Code: " << GetLastError()<<"\n";
    	}
    
    system("PAUSE");
    }
    

    EinGast schrieb:

    Wieso <windows> und nicht <windows.h>? Wieso kein <string>?

    Ansonsten funktioniert dein Code bei mir (als Admin ausgeführt und das hier beachtet). Was gibt denn RegDeleteKey bei dir überhaupt zurück? ERROR_ENVVAR_NOT_FOUND stammt höchstwahrscheinlich von woanders her.

    Ich verwende folgenden Compiler: CodeGear C++ 5.90 für Win32 C
    Da funktioniert auch #include <windows> und #include <string> braucht der hier auch nicht.


Anmelden zum Antworten