Write Property Data

When an Apply event occurs, an extension to the Applications snap-in stores its property information under the Properties element.

Code Example

The code to write property data is present in the AppExt.cpp. The following code example shows a simple registry property connected to a checkbox control. To write the properties reflected by the controls on your property page, replace this code example with your own code.

                  
                  IXMLDOMNode* pElmExampleProp = NULL;

                  // Find the "Reg" property element:
                  hr = pThis->m_pXmlDom->selectSingleNode( 
                     L"/Application/Properties/Reg[@id='exampleSetting']", 
                     &pElmExampleProp );
                  
                  if ( hr == S_FALSE )
                  {
                     // "Reg" element was not found, create:
                     hr = AddElement( pThis->m_pXmlDom, pElmProps, _T( "Reg" ), 
                        &pElmExampleProp );
                        
                     if ( hr == S_OK )
                     {
                        // Set the property ID. This identifies the property
                        // for later retreival or modification by this interface.
                        // The property ID is not used during configuration.
                        SetAttribute( pThis->m_pXmlDom, pElmExampleProp, 
                           _T( "id" ), _T( "exampleSetting" ) );
                     }
                  }
                  
                  if ( hr == S_OK )
                  {
                     // Set the registry property type:
                     SetAttribute( pThis->m_pXmlDom, pElmExampleProp, 
                        _T( "type" ), _T( "REG_DWORD" ) );

                     // Set the registry hive:
                     SetAttribute( pThis->m_pXmlDom, pElmExampleProp, 
                        _T( "hive" ), _T( "HKEY_CURRENT_USER" ) );

                     // Set the registry key path:
                     SetAttribute( pThis->m_pXmlDom, pElmExampleProp, 
                        _T( "key" ), 
                        _T( "Software\\Microsoft\\Group Policy\\Preferences\\Applications\\Example" ) );

                     // Set the registry property name:
                     SetAttribute( pThis->m_pXmlDom, pElmExampleProp, 
                        _T( "name" ), _T( "Setting" ) );

                     // Get the state of the control:
                     bool bChecked = ( IsDlgButtonChecked( hwndDlg, 
                        IDC_CHECK1 ) == BST_CHECKED ); 

                     // Set the registry property value:
                     SetAttribute( pThis->m_pXmlDom, pElmExampleProp, 
                        _T( "value" ), bChecked ? _T( "1" ) : _T( "0" ) );

                     pElmExampleProp->Release();
                  }