Search code examples
c++windows-mobileregistrypocketpc

Edit Registry Values


I want to change the registry values on the pocketPC. I ran the following code:

if(enabled)
{
    dwData = 120;
}
if(RegSetValueEx(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Control\\Power\\Timeouts\\BattSuspendTimeout"), 0, REG_DWORD, (LPBYTE)&dwData, sizeof(DWORD)))
{
    return FALSE;
}

but it doesn't shange the registry entry. Does anyone know how to set registry key values with c++?

Thanks!


Solution

  • There are a two problems with what you are doing:

    1: RegSetValueEx does not take a path, only a valuename. So you need to open the key path first.

    e.g.

    HKEY key;
    if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\Power\\Timeouts", 0, 0, &key))
    {
        if(RegSetValueEx(key, _T("BattSuspendTimeout"), 0, REG_DWORD, (LPBYTE)&dwData, sizeof(DWORD)))
        {
            RegCloseKey(key);
            return FALSE;
        }
    
        RegCloseKey(key);
    }
    

    2: That area of the registry requires Privileged code signing to work on all Windows Mobile devices. You can get away with it on most current touch-screen windows mobile devices if the user says "yes" to the unknown publisher question when the application is first run or installed. If you get a "Access Denied" error on the set, then you really need to be Privileged code signed for the set to work.