From 5284ea8b6b1fedd0f62cf4eb97e169e8946041ed Mon Sep 17 00:00:00 2001 From: mq1n Date: Sun, 27 Jun 2021 09:52:18 +0300 Subject: [PATCH] add internet connection check --- CMakeLists.txt | 2 +- src/main.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e27b8e..b0f5969 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,4 +35,4 @@ add_executable (${PROJECT_NAME} src/main.cpp ) -target_link_libraries(${PROJECT_NAME} PowrProf Tbs) +target_link_libraries(${PROJECT_NAME} PowrProf WinInet Tbs) diff --git a/src/main.cpp b/src/main.cpp index cea1cf9..4f729de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -503,6 +504,29 @@ int main(int, char* argv[]) std::cout << "WDDM check passed!" << std::endl; } + // Internet connection + { + std::cout << "Internet connection checking..." << std::endl; + + DWORD dwFlags = 0; + if (!InternetGetConnectedState(&dwFlags, 0)) + { + std::cerr << "InternetGetConnectedState failed with error: " << GetLastError() << std::endl; + std::system("PAUSE"); + return EXIT_FAILURE; + } + + const auto dwTestConnectionRet = InternetAttemptConnect(0); + if (dwTestConnectionRet != ERROR_SUCCESS) + { + std::cerr << "InternetAttemptConnect failed with error: " << GetLastError() << std::endl; + std::system("PAUSE"); + return EXIT_FAILURE; + } + + std::cout << "Internet connection check passed!" << std::endl; + } + std::cout << "All checks passed! Your system can be upgradable to Windows 11" << std::endl; std::system("PAUSE"); return EXIT_SUCCESS;