查MSDN,用SDK函数可以实现,代码如下,已验证可行:
void SetGlobalOffline(BOOL fGoOffline)
{
INTERNET_CONNECTED_INFO ci;
memset(&ci, 0, sizeof(ci));
if(fGoOffline)
{
ci.dwConnectedState = INTERNET_STATE_DISCONNECTED_BY_USER;
ci.dwFlags = ISO_FORCE_DISCONNECTED;
}
else
{
ci.dwConnectedState = INTERNET_STATE_CONNECTED;
}
InternetSetOption(NULL,
INTERNET_OPTION_CONNECTED_STATE, &ci, sizeof(ci));
}