F
F
Firewoll2020-05-02 22:19:30
C++ / C#
Firewoll, 2020-05-02 22:19:30

Does not write to the c++ registry. What to do?

Hello friends, I haven’t been sleeping for 2 days trying to implement a c ++ registry entry for auto start, below I will present the code to you, the problem is that it does not write to the registry.

BOOL AutoRunViaRegedit(wchar_t* path) {
  HKEY hKey;

  if (RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS) {
    RegSetValueEx(hKey, L"Test", 0, REG_SZ, (LPBYTE)path, sizeof(path));

    RegCloseKey(hKey);
  }

  return true;
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Firewoll, 2020-05-03
@Firewoll

I found a problem in 19 studios, over choosing all platforms, and not 32 bit when building, then everything works.

#
#, 2020-05-02
@mindtester

wchar_t* pathpointer?
sizeof(path)pointer size?

ps
чему равен размер указателя?
как определить реальный размер строки?
что делать, если захочется записать не строковые данные?

A
Alexander Ananiev, 2020-05-02
@SaNNy32

Does the program compile as x86? If yes, and windows x64, then you need to specify which registry branch to write to. This is done through the KEY_WOW64_64KEY flag.
Read more here: https://docs.microsoft.com/en-us/windows/win32/sys...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question