C++ Registry Add nothing happen

1

I have admin rights on PC, windows and try add registry DWORD key with CMD and ShellExecute. All others commands via this way is working, but not Reg Add.

ShellExecute(0, "open", "cmd.exe", "/C reg add \"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\SpecialAccounts\\Userlist\" /v username /t REG_DWORD /d 0 /f", 0, SW_HIDE);

When i try nothing happens. Why?

I have tried running the above command directly in the cmd with success, but when running my application the key is not added.

Thx.

Ok guys i try use another way using this code:

HKEY hKey;
        LPCSTR sKeyPath;
        int iResult;

        sKeyPath = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\SpecialAccounts\\Userlist";
        iResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyPath, NULL, KEY_ALL_ACCESS, &hKey);
        DWORD value = 0x00000000;
        iResult = RegSetValueEx(hKey, "username", NULL, REG_DWORD, (const BYTE*)&value, sizeof(value));
        RegCloseKey(hKey);

Don't work too :( I try this instead, but fail

HKEY hKey;
_TCHAR sKeyPath[] = _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\SpecialAccounts\\Userlist");

RegCreateKeyEx(HKEY_LOCAL_MACHINE, sKeyPath, 0, NULL, REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
RegSetValueEx(hKey, _T("username"), 0, REG_DWORD, (BYTE*)_T("000000"), sizeof(_T("000000")));
c++
windows
visual-c++
cmd
regedit
asked on Stack Overflow Mar 29, 2019 by Bobby • edited Mar 29, 2019 by Thomas Matthews

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0