// First of all, check the application is already authorized; FW_ERROR_CODE nError = this->IsAppEnabled( lpszProcessImageFileName, bAppEnable ); if( nError != FW_NOERROR ) throw nError;
// Only add the application if it isn't authorized if( bAppEnable == FALSE ) { // Retrieve the authorized application collection hr = m_pFireWallProfile->get_AuthorizedApplications( &pFWApps ); if( FAILED( hr )) throw FW_ERR_AUTH_APPLICATIONS;
// Create an instance of an authorized application hr = CoCreateInstance( __uuidof(NetFwAuthorizedApplication), NULL, CLSCTX_INPROC_SERVER, __uuidof(INetFwAuthorizedApplication), (void**)&pFWApp); if( FAILED( hr )) throw FW_ERR_Create_APP_INSTANCE;
// Allocate a BSTR for the Process Image FileName bstrProcessImageFileName = SysAllocString( lpszProcessImageFileName ); if( SysStringLen( bstrProcessImageFileName ) == 0) throw FW_ERR_SYS_ALLOC_STRING;
// Set the process image file name hr = pFWApp->put_ProcessImageFileName( bstrProcessImageFileName ); if( FAILED( hr ) ) throw FW_ERR_PUT_PROCESS_IMAGE_NAME;
// Allocate a BSTR for register name bstrRegisterName = SysAllocString( lpszRegisterName ); if( SysStringLen( bstrRegisterName ) == 0) throw FW_ERR_SYS_ALLOC_STRING; // Set a registered name of the process hr = pFWApp->put_Name( bstrRegisterName ); if( FAILED( hr )) throw FW_ERR_PUT_REGISTER_NAME;
// Add the application to the collection hr = pFWApps->Add( pFWApp ); if( FAILED( hr )) throw FW_ERR_ADD_TO_COLLECTION; } } catch( FW_ERROR_CODE nError ) { ret = nError; }