| julof26 (56) | |||
|
hi everyone :) Ive got problem with func RegDeleteKeyA(). Ive created some registry but when I try to remove it with this dunc I get error, returing 2, which means file not found. This is strange cause i use the same path. This is my code (Im using QtSDK library):
The registry is already created, Ive checked that its where it should be (HKCU\software\microsoft\windows\currentversion\run), theres registry called NoteBlock with string value C:\Program Files\Aspect\NoteBlock\NoteBlock.exe. Im stuck here for some time now so I think someone can help me? .) thanks for every reply. | |||
|
|
|||
| andywestken (1950) | |
|
From WinError.h ERROR_FILE_NOT_FOUND = 2 It's reused by the Registry API to say that a key or value cannot be found. Anyway, your code is creating a value and then trying to remove a subkey. As there's no subkey with the right name, just a value, it fails. Did you want a value? Then use RegDeleteValue to delete it. Otherwise modify your code to create a subkey. Andy | |
|
Last edited on
|
|
| kbw (5375) | |||||
|
All those casts. Are you sure about all that stuff? Let's take one: http://msdn.microsoft.com/en-gb/library/windows/desktop/ms724897(v=vs.85).aspx
Then you're code:
The delete is failing, but what's the error code? Can you fix all that stuff before moving on please. Are you aware of the responsibility you take on when you use a cast in C++? | |||||
|
|
|||||
| julof26 (56) | |||
|
first of all thank you both for spending time by replying me :) then to andywestken (1808): in the if block Im creating registry in the else block I want that registry to be fully removed not just its value. removing the value will made the thing but I dont want the user to have useless registry with no value so Id rather remove the whole registry. for example the user installs my app then go through the settings and see option start on startup. Since this application is made for runnig all the time the computer is turned on he decide to use this feature and he check the checkbox start on startup and hits 'set' button (thats when the if block proceeds). After some time he realizes that too many apps are starting with his system and he want that my application start with system no more. he opens the setting again and uncheck the start on startup checkbox, and the else block proceeds but it popups with this error that registry cannot be removed, which says file not found. But the registry is created so i dont see the problem :). for kbw (5260) I just realised that these casts here are useless so just changed the code a little bit :)
| |||
|
Last edited on
|
|||
| andywestken (1950) | |||
|
The phrase "remove the whole registry" is a bit frightening. If you removed the whole of the registry, you'd take out Windows! As it stands, your code is opening the (exisiting) Run key and adding a value. So all you need to do later is remove this value. You have not created a subkey, so there's nothing else you need to do to clean up. And you shouldn't remove the Run key, as that's a standard Windows key. As I said before, you're creating a value not a subkey. The call RegSetValueExA(hkey, subkey, ... is creating a value, not a subkey, even though your variable is named subkey. The second param of this API call is the value name.
(nicked from MSDN) As you've create a value, what you need to delete is also a value! Andy | |||
|
Last edited on
|
|||
| julof26 (56) | |
|
oh thanks, now I understand. I got some mess in my registry knowledge :D That thing about removing windows is a bit funny :D. Now I think I get it so thanks again :) Tried that and work perfectly. | |
|
|
|