Old code that I ported from Delphi in like 2009... not much use for it anymore.
Edit: Could be used for any service really with simple modifications.
#include <windows.h>
#include <stdio.h>
int WFDisable( bool bEnable );
int main()
{
WFDisable( false ); //disable
Sleep( 5000 );
WFDisable( true ); //enable
return( getchar( ) );
}
int WFDisable( bool bEnable )
{
OSVERSIONINFO osvi;
SERVICE_STATUS sStatus;
BOOL bControl;
LPCTSTR cService;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if( GetVersionExA( &osvi ) != 0 ) {
if( osvi.dwMajorVersion > 5 ) {
cService = "MpsSvc";
} else {
cService = "SharedAccess";
}
} else {
return( 1 );
}
SC_HANDLE hManager = OpenSCManager( NULL, NULL, 0xF003F );
if( hManager == NULL ) {
return( 2 );
}
SC_HANDLE hService = OpenService( hManager, cService, 0xF01FF );
if( hService == NULL ) {
return( 3 );
}
if( bEnable == true ) {
bControl = StartService( hService, 0, NULL ); //start
} else {
bControl = ControlService( hService, 0x00000001, &sStatus ); //stop
}
if( bControl == 0 ) {
return( 4 );
}
CloseServiceHandle( hManager );
CloseServiceHandle( hService );
return( 0 );
}