Results 1 to 6 of 6

Thread: Windows not automatically detecting registry changes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Windows not automatically detecting registry changes

    I have an app that disables some of the log on features, like HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr, and the registry will see the changes, but Windows won't acknowledge the changes until my app closes. However, if I make the changes directly into the registry editor, Windows will acknowledge the changes. What's the deal? Is this atleast supposed to happen, because if so I don't think it will hurt the functionality of my app; I just don't want to have to worry about differences between different systems.

    I'm using Windows XP by the way, and this app is designed for XP.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    make sure you're closing the registry key!
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Hah, thanks for that thought, but I've already looked into that. Same problem.

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Why not post some code up and we'll have a look see.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Registry Code:
    PHP Code:
    BOOL SaveDWORD (HKEY lpszKeyLPCTSTR lpszSubkeyLPCTSTR lpszValueNameDWORD dwValue)
    {
        
    //Registry Key Handle
        
    HKEY    CurKey;

        
    BOOL    fRes=FALSE;

        if (
    lpszSubkey != NULL && lpszValueName != NULL)
        {
            if (
    strlen(lpszSubkey) > && strlen(lpszValueName) > 0)
            {
                if (
    RegOpenKey(lpszKeylpszSubkey, &CurKey) == ERROR_SUCCESS)
                {
                    if (
    RegSetValueEx(CurKeylpszValueName0REG_DWORD, (PBYTE)&dwValuesizeof(DWORD)) == ERROR_SUCCESS)
                        
    fRes TRUE;
                }
                else
                {
                    
    // Create new key
                    
    if (RegCreateKey(lpszKeylpszSubkey, &CurKey) == ERROR_SUCCESS)
                    {
                        if (
    RegSetValueEx(CurKeylpszValueName0REG_DWORD, (PBYTE)&dwValuesizeof(DWORD)) == ERROR_SUCCESS)
                            
    fRes TRUE;
                    }
                }
            }
        }
        
    RegCloseKey (CurKey);
        return 
    fRes;

    Program close code:
    PHP Code:
    PostQuitMessage(0); 
    Registry settings being modified:

    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableChangePassword
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableLockWorkstation
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\NoLogoff

    To reiterate: I know the save code works because the registry values do change; the issue is that Windows (XP) doesn't aknowledge the changes with the login screen until my app closes.

    As bad as it may look, I'm not trying to write a virus or anything Another question that goes with this, how do I determine the logged on user's permissions (login name, administrative account or limited acount, registry permissions)? Thanks.

  6. #6
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    RegOpenKey, RegCreateKey, and RegSetValue are 16-bit
    Windows and should not be used anymore.

    RegOpenKeyEx, RegCreateKeyEx, and RegSetValueEx should be used.
    Code:
    BOOL SaveDWORD(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwValue)
    {
    
    	HKEY	hCurKey;
    	BOOL	bRet = FALSE;
    
    	if (lpSubKey != NULL && lpValueName != NULL)
    	{
    		if (strlen(lpSubKey) > 0 && strlen(lpValueName) > 0)
    		{
    			if (RegOpenKeyEx(hKey, lpSubKey, 0, KEY_SET_VALUE, &hCurKey) == ERROR_SUCCESS)
    			{
    				if (RegSetValueEx(hCurKey, lpValueName, 0, REG_DWORD, 
    					(LPBYTE)&dwValue, sizeof(DWORD)) == ERROR_SUCCESS)
    				{
    					bRet = TRUE;
    				}
    			}
    			else
    			{
    				if (RegCreateKeyEx(hKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE,
    					KEY_SET_VALUE, NULL, &hCurKey, NULL) == ERROR_SUCCESS)
    				{
    					if (RegSetValueEx(hCurKey, lpValueName, 0, REG_DWORD, 
    						(LPBYTE)&dwValue, sizeof(DWORD)) == ERROR_SUCCESS)
    					{
    						bRet = TRUE;
    					}
    				}
    			}
    		}
    	}
    	
    	RegCloseKey(hCurKey);
    	
    	return bRet;
    }
    Last edited by wey97; Jul 28th, 2003 at 08:27 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width