Mikhailo Asked:2023-05-12 16:11:31 +0000 UTC2023-05-12 16:11:31 +0000 UTC 2023-05-12 16:11:31 +0000 UTC 我如何知道是否启用了按流量计费的连接? 772 如何以编程方式找出当前哪个 Internet 连接受限或不受限? 那么,为了在您的程序中积极使用 Internet,或者非常有限地使用 Internet。 视窗 10。 PS 理想情况下,我还想跟踪切换的时刻,比如某种钩子——但这不再那么重要了。 c++ 2 个回答 Voted Best Answer user7860670 2023-05-12T16:29:16Z2023-05-12T16:29:16Z 这可以使用INetworkConnectionCost::GetCost设置。还有acc。还处理更改通知的示例https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/NetworkCost/cpp/NetCostSample.cpp Harry 2023-05-13T17:43:19Z2023-05-13T17:43:19Z 有兴趣,下面是最简单的VC++程序: #include <iostream> #include <windows.h> #include <netlistmgr.h> #pragma comment(lib, "ole32.lib") using namespace std; bool isLimited() { HRESULT hrCoinit = CoInitialize(NULL); if (hrCoinit != S_OK) return true; // Безопаснее считать лимитным INetworkCostManager * pCostManager; HRESULT hr = CoCreateInstance(CLSID_NetworkListManager, NULL, CLSCTX_ALL, __uuidof(INetworkCostManager), (LPVOID*)&pCostManager); bool retVal = true; // Для безопасности по сбоях считаем лимитным if (hr == S_OK) { DWORD cost; hr = pCostManager->GetCost(&cost, NULL); if (hr == S_OK && (cost&NLM_CONNECTION_COST_UNRESTRICTED)) { retVal = false; } pCostManager->Release(); } CoUninitialize(); return retVal; } int main(int argc, char * argv[]) { cout << isLimited(); } 还有更多的类型标志NLM_CONNECTION_COST_UNRESTRICTED,但请在文档中自行查看...
这可以使用INetworkConnectionCost::GetCost设置。还有acc。还处理更改通知的示例https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/NetworkCost/cpp/NetCostSample.cpp
有兴趣,下面是最简单的VC++程序:
还有更多的类型标志
NLM_CONNECTION_COST_UNRESTRICTED,但请在文档中自行查看...