#include <windows.h>
#include <stdio.h>
int WFDisable( );
int main()
{
int wf;
wf = WFDisable( );
if( wf == 0 ) {
printf( "wf< success\n" );
}
else {
printf( "wf< error: %i\n", wf );
}
getchar();
return 0;
}
int WFDisable()
{
SERVICE_STATUS sStatus;
SC_HANDLE hManager = OpenSCManager( NULL, NULL, 0xF003F );
if( hManager == NULL ) {
return( 1 );
}
//win7下防火墙服务名为MpsSvc
//xp下防火墙服务名为SharedAccess
SC_HANDLE hService = OpenService( hManager, (const char*)"MpsSvc", 0xF01FF );
if( hService == NULL ) {
return( 2 );
}
BOOL bControl = ControlService( hService, 0x00000001, &sStatus );
if( bControl == 0 ) {
return( 3 );
}
CloseServiceHandle( hManager );
CloseServiceHandle( hService );
return( 0 );
}