BOOL PacketInstallDriver40() { PacketStopDriver40(); SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (schSCManager == NULL) { return FALSE; } TCHAR szFileFullPath[_MAX_PATH]; DWORD nResult = GetServiceSysFilePath(szFileFullPath, MAX_PATH); if (nResult == 0) { return FALSE; } SC_HANDLE schService = CreateService(schSCManager, _T(NPF_DRIVER_NAME_SMALL), NPF_SERVICE_DESC_TCHAR, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, szFileFullPath, NULL, NULL, NULL, NULL, NULL); if (schService == NULL) { int aaa = GetLastError(); return FALSE; } CloseServiceHandle(schSCManager); CloseServiceHandle(schService); return TRUE; }
int _tmain(int argc, _TCHAR* argv[]) { BOOL bSuccess = FALSE; BOOL bNoWindow = FALSE; SetConsoleTitle(_T("NPFInstall for Npcap ") _T(WINPCAP_VER_STRING) _T(" (http://npcap.org)")); vector<tstring> strArgs; tstring strTmp; for (int i = 0; i < argc; i++) { strTmp = argv[i]; if (strTmp == _T("-n")) { bNoWindow = TRUE; } else { strArgs.push_back(strTmp); } } if (bNoWindow) { ShowWindow(GetConsoleWindow(), SW_HIDE); } if (strArgs.size() == 1) { _tprintf(STR_COMMAND_USAGE); return -1; } else if (strArgs.size() >= 3) { _tprintf(STR_INVALID_PARAMETER); return -1; } else //strArgs.size() == 2 { if (strArgs[1] == _T("-i")) { bSuccess = PacketInstallDriver60(FALSE); if (bSuccess) { _tprintf(_T("Npcap LWF driver (standard version) has been successfully installed!\n")); return 0; } else { _tprintf(_T("Npcap LWF driver (standard version) has failed to be installed.\n")); return -1; } } else if (strArgs[1] == _T("-i2")) { bSuccess = PacketInstallDriver60(TRUE); if (bSuccess) { _tprintf(_T("Npcap LWF driver (WiFi version) has been successfully installed!\n")); return 0; } else { _tprintf(_T("Npcap LWF driver (WiFi version) has failed to be installed.\n")); return -1; } } else if (strArgs[1] == _T("-u")) { bSuccess = PacketStopDriver60(); if (bSuccess) { _tprintf(_T("Npcap LWF driver has been successfully uninstalled!\n")); return 0; } else { _tprintf(_T("Npcap LWF driver has failed to be uninstalled.\n")); return -1; } } else if (strArgs[1] == _T("-ii")) { bSuccess = PacketInstallDriver40(); if (bSuccess) { _tprintf(_T("NPF legacy driver has been successfully installed!\n")); return 0; } else { _tprintf(_T("NPF legacy driver has failed to be installed.\n")); return -1; } } else if (strArgs[1] == _T("-uu")) { bSuccess = PacketStopDriver40(); if (bSuccess) { _tprintf(_T("NPF legacy driver has been successfully uninstalled!\n")); return 0; } else { _tprintf(_T("NPF legacy driver has failed to be uninstalled.\n")); return -1; } } else if (strArgs[1] == _T("-il")) { bSuccess = InstallLoopbackAdapter(); if (bSuccess) { _tprintf(_T("Npcap Loopback adapter has been successfully installed!\n")); return 0; } else { _tprintf(_T("Npcap Loopback adapter has failed to be installed.\n")); return -1; } } else if (strArgs[1] == _T("-ul")) { bSuccess = UninstallLoopbackAdapter(); if (bSuccess) { _tprintf(_T("Npcap Loopback adapter has been successfully uninstalled!\n")); return 0; } else { _tprintf(_T("Npcap Loopback adapter has failed to be uninstalled.\n")); return -1; } } else if (strArgs[1] == _T("-iw")) { bSuccess = InstallWFPCallout(); if (bSuccess) { _tprintf(_T("Npcap WFP callout driver has been successfully installed!\n")); return 0; } else { _tprintf(_T("Npcap WFP callout driver has failed to be installed.\n")); return -1; } } else if (strArgs[1] == _T("-uw")) { bSuccess = UninstallWFPCallout(); if (bSuccess) { _tprintf(_T("Npcap WFP callout driver has been successfully uninstalled!\n")); return 0; } else { _tprintf(_T("Npcap WFP callout driver has failed to be uninstalled.\n")); return -1; } } else if (strArgs[1] == _T("-r")) { bSuccess = PacketRenableBindings(); if (bSuccess) { _tprintf(_T("Npcap driver's bindings have been successfully restarted!\n")); return 0; } else { _tprintf(_T("Npcap driver's bindings have failed to be restarted.\n")); return -1; } } else if (strArgs[1] == _T("-d")) { bSuccess = PacketIsServiceStopPending(); if (bSuccess) { _tprintf(_T("Npcap service is pending to stop!\n")); return 0; } else { _tprintf(_T("Npcap service is not pending to stop.\n")); return -1; } } else if (strArgs[1] == _T("-c")) { bSuccess = ClearDriverStore(); if (bSuccess) { _tprintf(_T("Npcap driver cache in Driver Store has been successfully cleaned up!\n")); return 0; } else { _tprintf(_T("Npcap driver cache in Driver Store has failed to be cleaned up.\n")); return -1; } } else if (strArgs[1] == _T("-wlan_check")) { vector<tstring> nstrAdapterGuids; nstrAdapterGuids = getWlanAdapterGuids(); if (nstrAdapterGuids.size() != 0) { _tprintf(_T("Wlan adapters: %s\n"), printArray(nstrAdapterGuids).c_str()); return 0; } else { _tprintf(_T("Wlan adapters: NULL\n")); return -1; } } else if (strArgs[1] == _T("-wlan_write_reg")) { bSuccess = writeWlanAdapterGuidsToRegistry(); if (bSuccess) { _tprintf(_T("Wlan adapters have been successfully written to registry!\n")); return 0; } else { _tprintf(_T("Wlan adapters have failed to be written to registry.\n")); return -1; } } else if (strArgs[1] == _T("-h")) { _tprintf(STR_COMMAND_USAGE); return -1; } else { _tprintf(STR_INVALID_PARAMETER); return -1; } } return 0; }
int _tmain(int argc, _TCHAR* argv[]) { BOOL bSuccess = FALSE; BOOL bVerbose = FALSE; SetConsoleTitle(NPF_SERVICE_DESC_TCHAR _T(" for packet capturing")); if (argc >= 2) { if (_tcscmp(_T("-h"), argv[1]) == 0) { bVerbose = TRUE; } } if (argc >= 3) { if (_tcscmp(_T("-v"), argv[2]) == 0) { bVerbose = TRUE; } else { _tprintf(STR_COMMAND_USAGE); return -1; } } if (!bVerbose) { ShowWindow(GetConsoleWindow(), SW_HIDE); } if (argc < 2) { _tprintf(STR_COMMAND_USAGE); return -1; } else //argc == 2 { if (_tcscmp(_T("-i"), argv[1]) == 0) { bSuccess = PacketInstallDriver60(); if (bSuccess) { _tprintf(_T("Npcap LWF driver has been successfully installed!\n")); return 0; } else { _tprintf(_T("Npcap LWF driver has failed the installation.")); return -1; } } else if (_tcscmp(_T("-u"), argv[1]) == 0) { bSuccess = PacketStopDriver60(); if (bSuccess) { _tprintf(_T("Npcap LWF driver has been successfully uninstalled!\n")); return 0; } else { _tprintf(_T("Npcap LWF driver has failed the uninstallation.")); return -1; } } else if (_tcscmp(_T("-ii"), argv[1]) == 0) { bSuccess = PacketInstallDriver40(); if (bSuccess) { _tprintf(_T("NPF legacy driver has been successfully installed!\n")); return 0; } else { _tprintf(_T("NPF legacy driver has failed the installation.")); return -1; } } else if (_tcscmp(_T("-uu"), argv[1]) == 0) { bSuccess = PacketStopDriver40(); if (bSuccess) { _tprintf(_T("NPF legacy driver has been successfully uninstalled!\n")); return 0; } else { _tprintf(_T("NPF legacy driver has failed the uninstallation.")); return -1; } } else if (_tcscmp(_T("-il"), argv[1]) == 0) { bSuccess = InstallLoopbackAdapter(); if (bSuccess) { _tprintf(_T("Npcap Loopback adapter has been successfully installed!\n")); return 0; } else { _tprintf(_T("Npcap Loopback adapter has failed the installation.")); return -1; } } else if (_tcscmp(_T("-ul"), argv[1]) == 0) { bSuccess = UninstallLoopbackAdapter(); if (bSuccess) { _tprintf(_T("Npcap Loopback adapter has been successfully uninstalled!\n")); return 0; } else { _tprintf(_T("Npcap Loopback adapter has failed the uninstallation.")); return -1; } } else if (_tcscmp(_T("-iw"), argv[1]) == 0) { bSuccess = InstallWFPCallout(); if (bSuccess) { _tprintf(_T("Npcap WFP callout driver has been successfully installed!\n")); return 0; } else { _tprintf(_T("Npcap WFP callout driver has failed the installation.")); return -1; } } else if (_tcscmp(_T("-uw"), argv[1]) == 0) { bSuccess = UninstallWFPCallout(); if (bSuccess) { _tprintf(_T("Npcap WFP callout driver has been successfully uninstalled!\n")); return 0; } else { _tprintf(_T("Npcap WFP callout driver has failed the uninstallation.")); return -1; } } else if (_tcscmp(_T("-r"), argv[1]) == 0) { bSuccess = PacketRenableBindings(); if (bSuccess) { _tprintf(_T("Npcap driver's bindings have been successfully restarted!\n")); return 0; } else { _tprintf(_T("Npcap driver's bindings have failed to restart.")); return -1; } } else if (_tcscmp(_T("-d"), argv[1]) == 0) { bSuccess = PacketIsServiceStopPending(); if (bSuccess) { _tprintf(_T("Npcap service is pending to stop!\n")); return 0; } else { _tprintf(_T("Npcap service is not pending to stop.")); return -1; } } else if (_tcscmp(_T("-h"), argv[1]) == 0) { _tprintf(STR_COMMAND_USAGE); return -1; } else { _tprintf(_T("Invalid parameter, type in \"NPFInstall -h\" for help.\n")); return -1; } } return 0; }