NetTunnelWindows/NetTunnelSDKTestApp/NetTunnelSDKTestApp.cpp

99 lines
3.6 KiB
C++
Raw Normal View History

// NetTunnelSDKTestApp.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "common.h"
#include <windows.h>
#include <iostream>
#include <tchar.h>
using namespace std;
int service_test() {
TCHAR szSvcName[] = _T("WireGuard");
SC_HANDLE schSCManager = nullptr;
SC_HANDLE schService = nullptr;
SERVICE_STATUS_PROCESS ssStatus;
DWORD dwOldCheckPoint = 0;
DWORD dwStartTickCount = 0;
DWORD dwWaitTime = 0;
DWORD dwBytesNeeded = 0;
// Get a handle to the SCM database.
schSCManager = OpenSCManager(nullptr, // local computer
nullptr, // ServicesActive database
SC_MANAGER_ALL_ACCESS); // full access rights
if (nullptr == schSCManager) {
printf("OpenSCManager failed (%d)\n", GetLastError());
}
// Get a handle to the service.
schService = OpenService(schSCManager, // SCM database
szSvcName, // name of service
SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS); // full access
if (schService == nullptr) {
printf("OpenService failed (%d)\n", GetLastError());
CloseServiceHandle(schSCManager);
}
// Check the status in case the service is not stopped.
if (!QueryServiceStatusEx(schService, // handle to service
SC_STATUS_PROCESS_INFO, // information level
(LPBYTE)&ssStatus, // address of structure
sizeof(SERVICE_STATUS_PROCESS), // size of structure
&dwBytesNeeded)) // size needed if buffer is too small
{
printf("QueryServiceStatusEx failed (%d)\n", GetLastError());
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
} else {
// Check if the service is already running. It would be possible
// to stop the service here, but for simplicity this example just returns.
printf("Service status: ");
switch (ssStatus.dwCurrentState) {
case SERVICE_STOPPED:
case SERVICE_STOP_PENDING:
printf("Stop");
break;
case SERVICE_PAUSED:
case SERVICE_PAUSE_PENDING:
printf("Pause");
break;
case SERVICE_CONTINUE_PENDING:
case SERVICE_RUNNING:
case SERVICE_START_PENDING:
printf("Running");
break;
}
cout << endl;
}
cin.get();
return 0;
}
int main() {
//ShowRouteTable();
//NetShare();
//GetInterface();
CryptoExample();
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门使用技巧:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件