Results 1 to 3 of 3

Thread: Update registry changes Automatically

  1. #1
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default Update registry changes Automatically

    I'm making changes to the registry and they work (because I can see the changes in the registry), but I can't seem to figure out a way to push out a update or restore so that the changes are applied automatically without a restart\logoff & logon.

    I tried several things, and I can't seem to figure it out. Here is some "ugly" code that I was trying to see if I can push the updates, but nothing seems to work.

    Basically I have a plain desktop with the background set as black (0 0 0) <-- REG_SZ
    I'm changing it to (123 123 123) a greyish color

    When I restart or logon\logoff the changes occur as necessary, but obviously not through my program.
    Also tried closing explorer.exe and restarting it and still no go.

    Any ideas? Here is my code:

    PHP Code:
    int key1()
    {
        
    HKEY hKey1;


        if(
    ERROR_SUCCESS == RegOpenKeyExW(HKEY_CURRENT_USERL"Control Panel\\Desktop"0KEY_WRITE, &hKey1))
        {    
            
    TCHAR value1[] = _T("none");
            
    DWORD dwLength1 wcslen((const wchar_t *)value1) + 1;
            
    DWORD dwLength1a dwLength1 sizeof(WCHAR);


            if(
    ERROR_SUCCESS == RegSetValueEx(hKey1"Wallpaper"0REG_SZ, (const BYTE *)value1dwLength1a))
            { 
                
    SystemParametersInfoSPI_GETUIEFFECTStrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
                
    SystemParametersInfoSPI_SETUIEFFECTStrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
                
    SystemParametersInfoSPI_GETSHOWIMEUItrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
                
    SystemParametersInfoSPI_SETSHOWIMEUItrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );


                
    SendMessage(HWND_BROADCASTWM_SETTINGCHANGE0, (LPARAM)"Registry");
                
    SystemParametersInfo(SPI_SETDESKWALLPAPER0""SPIF_SENDCHANGE); 
                
    SendMessage(HWND_BROADCASTWM_SETTINGCHANGE00); 
                
    SystemParametersInfo(SPI_SETDESKWALLPAPER0NULLSPIF_SENDWININICHANGE);
                
    SendMessage(HWND_BROADCASTWM_WININICHANGE |  WM_SETTINGCHANGE00);
                
    SystemParametersInfo(SPI_SETDESKWALLPAPER SPIF_SENDCHANGE 0NULLSPIF_UPDATEINIFILE SPIF_SENDCHANGE SPIF_SENDWININICHANGE);


            
    RegCloseKey (hKey1);
                return 
    0;
            } 


            
    RegCloseKey(hKey1);
        }
        return 
    0;
    }


    int key2()
    {
        
    HKEY hKey2;    


        if(
    ERROR_SUCCESS == RegOpenKeyExW(HKEY_CURRENT_USERL"Control Panel\\Colors"0KEY_WRITE, &hKey2))
        {
            
    TCHAR value2[] = _T("123 123 123");


            
    DWORD dwLength2 strlen(value2) + 1;
            
    DWORD dwLength2a dwLength2 sizeof(CHAR);
            
            if(
    ERROR_SUCCESS == RegSetValueEx(hKey2"Background"0REG_SZ, (const BYTE *)value2,  dwLength2a))
            { 
                
    SystemParametersInfoSPI_GETUIEFFECTStrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
                
    SystemParametersInfoSPI_SETUIEFFECTStrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
                
    SystemParametersInfoSPI_GETSHOWIMEUItrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
                
    SystemParametersInfoSPI_SETSHOWIMEUItrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );


                
    SendMessage(HWND_BROADCASTWM_SETTINGCHANGE0, (LPARAM)"Registry");
                
    SystemParametersInfo(SPI_SETDESKWALLPAPER0""SPIF_SENDCHANGE); 
                
    SendMessage(HWND_BROADCASTWM_SETTINGCHANGE00); 
                
    SystemParametersInfo(SPI_SETDESKWALLPAPER0NULLSPIF_SENDWININICHANGE);
                
    SendMessage(HWND_BROADCASTWM_WININICHANGE |  WM_SETTINGCHANGE00);
                
    SystemParametersInfo(SPI_SETDESKWALLPAPER SPIF_SENDCHANGE 0NULLSPIF_UPDATEINIFILE SPIF_SENDCHANGE SPIF_SENDWININICHANGE);


                
    RegCloseKey (hKey2); 
                return 
    0
            } 


            
    RegCloseKey (hKey2); 
        }
        return 
    0;
    }
    DWORD WINAPI ThreadRoutine(LPVOID lpArg)
    {
        
    HRESULT hr;
        
    IActiveDesktoppActiveDesktop 0;


        while(
    1)
        {
            
    CoInitialize);


            
    hr CoCreateInstance(CLSID_ActiveDesktopNULLCLSCTX_INPROC_SERVERIID_IActiveDesktop, (void**) &pActiveDesktop);


            if(
    FAILED(hr))
            {
                
    // Creating ActiveDesktop interface pointer failed.
                
    AfxMessageBox_T("Error Occurred!"));
            }


            
    key1();
            
    key2();


            
    SystemParametersInfoSPI_GETUIEFFECTStrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
            
    SystemParametersInfoSPI_SETUIEFFECTStrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
            
    SystemParametersInfoSPI_GETSHOWIMEUItrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );
            
    SystemParametersInfoSPI_SETSHOWIMEUItrue0SPIF_UPDATEINIFILE SPIF_SENDCHANGE );


            
    SendMessage(HWND_BROADCASTWM_SETTINGCHANGE0, (LPARAM)"Registry");
            
    SystemParametersInfo(SPI_SETDESKWALLPAPER0""SPIF_SENDCHANGE); 
            
    SendMessage(HWND_BROADCASTWM_SETTINGCHANGE00); 
            
    SystemParametersInfo(SPI_SETDESKWALLPAPER0NULLSPIF_SENDWININICHANGE);
            
    SendMessage(HWND_BROADCASTWM_WININICHANGE |  WM_SETTINGCHANGE00);
            
    SystemParametersInfo(SPI_SETDESKWALLPAPER SPIF_SENDCHANGE 0NULLSPIF_UPDATEINIFILE SPIF_SENDCHANGE SPIF_SENDWININICHANGE);


            
    // Apply changes to refresh desktop.
            
    pActiveDesktop->ApplyChangesAD_APPLY_ALL );


            
    // Release the interface pointer.
            
    pActiveDesktop->Release();


            
    CoUninitialize();
        }


        return 
    1;

    I have also tried this:
    PHP Code:
    %SystemRoot%\System32\RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,,True 
    still no go..
    I would like this to work universally on any Windows platform. At home I have XP Pro x86 and at work I use Win7 Ultimate x64 (So I can test to make sure it works properly)

    Thanks in advance!

  2. #2

    Default

    There doesn't really seem to be a nice way of forcing Windows to load the settings from registry.
    However, there is a system call for changing the colors of the current session.
    I put this function together:
    PHP Code:
    DWORD changeCurrentBackground(int rint gint b) {
        
    COLORREF color RGB(rgb);
        
    int aElements[1] = {COLOR_BACKGROUND};
        
    DWORD aOldColor;
        
    DWORD aNewColors[1] = { color };

        
    aOldColor GetSysColor(aElements[0]); 
        
    SetSysColors(1aElementsaNewColors);
        
        return 
    aOldColor;

    Example call:
    PHP Code:
    changeCurrentBackground(000); 
    Which works like a charm under Windows 7 and changes the current session's background color to black.
    =|UWS|=|SA|Vince - Head Serveradmin - mohaa.uwsclan.us (MOH:AA - FT)

  3. #3
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Wargamer, you've been idling on me for a bit now haha.

    Anywho, with regards to what you wrote above, yes I'm VERY familiar with that method, however as you said it only changes the session. I've had my share of fun on it and you can read all about it here:
    http://www.x-null.net/forums/showthr...per-on-the-fly

    On another note, I've REALLY been digging myself into some hard core Windows API stuff. I'm really enjoying this and actually learning alot about how Windows handles "stuff". There is so much to learn, and on that note, I have come to the conclusion even after seeing on several forums & MSDN, there is NO documented way of doing what I am trying to do... YAY!!

    The good news is, if I figure this out, I will create something that few (and possibly none) have done before. I haven't gotten any responses from people on GD that allowed me to move any further than I have already gone. Which makes me think that maybe this really is a "easter egg" to solve.

    I'll see where I get with this.

    Also I would use the SetSysColors() route, but if you see my thread in the link above, the only reason I'm looking at alternative routes is because what I'm trying to do is refresh the window constantly for the color changes and this causes the icons to flicker. And from what I can tell there is no proper way to get a handle on the icons to prevent them from being updated with the color_background when I send a update via HWND_BROADCAST.

    If you have any info that I don't know though, I would really be interested in hearing more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •