//------------------------------------------------------------------------ // UninstallLSP() // // This is called if the msrlsp is already installed and we want to // remove it from the Winsock2 WSP chains. //------------------------------------------------------------------------ void UninstallLSP() { int iError; int iStatus; iStatus = WSCDeinstallProvider( (GUID*)&RestrictedProviderChainId,&iError ); iStatus = WSCDeinstallProvider( (GUID*)&LayeredProviderGuid, &iError); }
BOOL RemoveTransportProviderCallback( LPTSTR IniFile, LPTSTR SectionName, DWORD Context ) /*++ Routine Description: Callback routine for EnumProviderSections() that removes the transport service provider described by the given .INI file section. Arguments: IniFile - The name of the .INI file describing the transport provider. SectionName - The name of the .INI file section for this provider. Context - Actually contains behaviour control options (OPTION_FLAG_*). Return Value: BOOL - TRUE if successful, FALSE otherwise. --*/ { TCHAR providerName[MAX_INIFILE_LINE]; TCHAR providerIdString[MAX_INIFILE_LINE]; DWORD length; INT result; INT error; GUID providerId; RPC_STATUS status; BOOL ignoreErrors; // // Let the user know what we're up to. // _tprintf( TEXT("Removing %s\n"), SectionName ); // // Determine if we should ignore errors. If so, then this routine // will always return TRUE. // ignoreErrors = ( ( Context & OPTION_FLAG_IGNORE_ERRORS ) != 0 ); // // Read the provider name & ID. // length = GetPrivateProfileString( SectionName, TEXT("ProviderName"), TEXT(""), providerName, sizeof(providerName) / sizeof(providerName[0]), IniFile ); if( length == 0 ) { _tprintf( TEXT("ERROR: missing ProviderName key\n") ); return ignoreErrors; } length = GetPrivateProfileString( SectionName, TEXT("ProviderId"), TEXT(""), providerIdString, sizeof(providerIdString) / sizeof(providerIdString[0]), IniFile ); if( length == 0 ) { _tprintf( TEXT("ERROR: missing ProviderId key\n") ); return ignoreErrors; } // // Build the GUID. // status = UuidFromString( providerIdString, &providerId ); if( status != RPC_S_OK ) { _tprintf( TEXT("ERROR: invalid ProviderId %s\n"), providerIdString ); return ignoreErrors; } // // Remove it. // result = WSCDeinstallProvider( &providerId, &error ); if( result == SOCKET_ERROR ) { _tprintf( TEXT("Cannot remove %s, error %d\n"), providerName, error ); return ignoreErrors; } return TRUE; } // RemoveTransportProviderCallback
// // Function: DeinstallProvider // // Description: // This is a wrapper for the WSCDeinstallProvider* functions. Depending on // which Winsock catalog is specified, this routine calls the right uninstall // function. // int DeinstallProvider( WINSOCK_CATALOG Catalog, // Which Winsock catalog to operate on GUID *Guid // GUID of provider to remove ) { INT ErrorCode, rc; #ifdef _WIN64 if ( LspCatalogBoth == Catalog ) { // Remove from 64-bit catalog rc = WSCDeinstallProvider( Guid, &ErrorCode ); if ( SOCKET_ERROR == rc ) { fprintf( stderr, "DeinstallProvider: WSCDeinstallProvider failed: %d\n", ErrorCode ); } // Remove from the 32-bit catalog rc = WSCDeinstallProvider32( Guid, &ErrorCode ); if ( SOCKET_ERROR == rc ) { fprintf( stderr, "DeinstallProvider: WSCDeinstallProvider32 failed: %d\n", ErrorCode ); } } else if ( LspCatalog64Only == Catalog ) { // Remove from 64-bit catalog rc = WSCDeinstallProvider( Guid, &ErrorCode ); if ( SOCKET_ERROR == rc ) { fprintf( stderr, "DeinstallProvider: WSCDeinstallProvider failed: %d\n", ErrorCode ); } } else { // Remove from the 32-bit catalog rc = WSCDeinstallProvider32( Guid, &ErrorCode ); if ( SOCKET_ERROR == rc ) { fprintf( stderr, "DeinstallProvider: WSCDeinstallProvider32 failed: %d\n", ErrorCode ); } } #else if ( LspCatalog32Only == Catalog ) { // Remove from the 32-bit catalog rc = WSCDeinstallProvider( Guid, &ErrorCode ); if ( SOCKET_ERROR == rc ) { fprintf( stderr, "DeinstallProvider: WSCDeinstallProvider failed: %d\n", ErrorCode ); } } else { fprintf( stderr, "Unable to remove providers in 64-bit catalog from 32-bit process!\n" ); return SOCKET_ERROR; } #endif return NO_ERROR; }
JNIEXPORT jint JNICALL Java_com_act365_net_SocketWrenchSession__1deinstallProvider( JNIEnv* env , jclass , jint protocol ) { int nDeinstalled = 0 ; #ifdef WIN32 int i = -1 ; // Find the installed service providers for the given protocol. int protocolList[1]; protocolList[0] = (int) protocol ; if( ( nProtocols = WSAEnumProtocolsW( protocolList , protocolBuffer , & protocolBufferSize ) ) == SOCKET_ERROR ){ jclass exceptionClass = env -> FindClass("java/net/SocketException"); SocketUtils::throwError( env , exceptionClass , "WSAEnumProtocols()" ); env -> DeleteLocalRef( exceptionClass ); return nDeinstalled ; } // Find the path of the DLL in which the services are implemented. // (It's assumed that they're all implemented in a single MS DLL). int errorCode = 0 , dllPathLength = maxDllPathLength ; if( nProtocols > 0 ){ WSCGetProviderPath( & protocolBuffer[0].ProviderId , dllPath , & dllPathLength , & errorCode ); } if( errorCode > 0 ){ jclass exceptionClass = env -> FindClass("java/net/SocketException"); SocketUtils::throwError( env , exceptionClass , "WSCGetProviderPath()" ); env -> DeleteLocalRef( exceptionClass ); return nDeinstalled ; } // Deinstall. while( ++ i < nProtocols && ! errorCode ){ nDeinstalled += WSCDeinstallProvider( & protocolBuffer[i].ProviderId , & errorCode ); } if( errorCode > 0 ){ jclass exceptionClass = env -> FindClass("java/net/SocketException"); SocketUtils::throwError( env , exceptionClass , "WSCDeinstallProvider()" ); env -> DeleteLocalRef( exceptionClass ); } #endif return nDeinstalled ; }