-2

Hello i need to do this command on c++:

reg delete "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control" /v SystemStartOptions /f

And i tried using system("");

system("reg delete ""HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control"" /v SystemStartOptions /f");

But im getting this error:

ERROR: The system was unable to find the specified registry key or value.

How i can fix this? I think problem is that double quotes in (""HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control"") becuase that command works on cmd. How i can do it correctly?

  • You would need to mask the quotation mark with a backslash, simply doubling will have no effect. – gerum May 08 '22 at 18:57
  • 2
    *Hello i need to do this command on c++:* No you don't. You need to learn how to [delete a value from the registry directly from C++](https://stackoverflow.com/questions/29058782/delete-key-from-registry-hkey-local-machine). Or perhaps [like this](https://stackoverflow.com/questions/2991648/deleting-all-values-under-a-specific-registry-key). – Andrew Henle May 08 '22 at 18:57
  • 1
    the inner " should be `\"` – QuentinUK May 08 '22 at 18:59
  • 1
    [Rules for C++ string literals escape character](/questions/10220401/rules-for-c-string-literals-escape-character) – Deduplicator May 08 '22 at 19:00
  • It looks like you've imported knowledge from another language, [maybe C#](https://stackoverflow.com/questions/1928909/can-i-escape-a-double-quote-in-a-verbatim-string-literal)? In C++, an expression like `"delete ""HKEY"" /v"` (to shorten your example) is parsed as three string literals: `"delete "` `"HKEY"` `" /v"`. Adjacent string literals are then concatenated: `"delete HKEY /v"`. Just an example of a pitfall of mixing languages. ;) – JaMiT May 08 '22 at 19:47

0 Answers0