Skip to content

Commit

Permalink
Added "-kill_proc_poite" option to NPFInstall.exe to kill all process…
Browse files Browse the repository at this point in the history
…es that are using Npcap DLLs politely.
  • Loading branch information
hsluoyz committed Dec 8, 2016
1 parent 3b7ff17 commit 05aaf42
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
19 changes: 18 additions & 1 deletion packetWin7/NPFInstall/NPFInstall/NPFInstall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ _T(" -r2\t\t\t: Restart all bindings (with Wi-Fi support)\n")\
_T(" -d\t\t\t: Detect whether the driver service is pending to stop\n")\
_T(" -check_dll\t\t: Detect whether the Npcap DLLs are still used by any processes, will list them if yes\n")\
_T(" -kill_proc\t\t: Terminate all the processes that are still using Npcap DLLs\n")\
_T(" -kill_proc_soft\t: Gracefully terminate all the processes that are still using Npcap DLLs (only for GUI processes, CLI processes will still be terminiated immediatelly)\n")\
_T(" -kill_proc_soft\t: Gracefully terminate all the processes that are still using Npcap DLLs (only for GUI processes, CLI processes will not be terminated)\n")\
_T(" -kill_proc_polite\t: Politely terminate all the processes that are still using Npcap DLLs (wait for 15 seconds for GUI processes to close themselves, CLI processes will still be terminiated immediatelly)\n")\
_T(" -c\t\t\t: Clear all the driverstore cache for the driver\n")\
_T(" -wlan_check\t\t: Check whether this machine owns a wireless adapter\n")\
_T(" -wlan_write_reg\t: Write the names of all wireless adapters to registry\n")\
Expand Down Expand Up @@ -541,6 +542,22 @@ int _tmain(int argc, _TCHAR* argv[])
goto _EXIT;
}
}
else if (strArgs[1] == _T("-kill_proc_polite"))
{
bSuccess = killInUseProcesses_Polite();
if (bSuccess)
{
_tprintf(_T("All the processes that are still using Npcap DLLs have been successfully terminated politely!\n"));
nStatus = 0;
goto _EXIT;
}
else
{
_tprintf(_T("Some of the processes that are still using Npcap DLLs have failed to be terminated politely.\n"));
nStatus = -1;
goto _EXIT;
}
}
else if (strArgs[1] == _T("-c"))
{
bSuccess = ClearDriverStore();
Expand Down
29 changes: 27 additions & 2 deletions packetWin7/NPFInstall/NPFInstall/ProcessUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ BOOL killProcess(DWORD dwProcessID)
}
else
{
TRACE_PRINT1("killProcess::TerminateProcess: succeeds, dwProcessID = %d.", dwProcessID);
TRACE_EXIT();
return TRUE;
}
Expand Down Expand Up @@ -342,20 +343,20 @@ BOOL killProcess_Soft(DWORD dwProcessID)
{
TRACE_ENTER();

tstring strSuccess = _T("SUCCESS");

tstring strCommand = _T("taskkill /pid ");
strCommand += itos(dwProcessID);

tstring strResult = executeCommand((TCHAR*)strCommand.c_str());

if (_tcsncmp(strResult.c_str(), _T("SUCCESS"), _tcslen(_T("SUCCESS"))) == 0)
{
TRACE_PRINT1("killProcess_Soft: gracefully kill process, bResult = 1, dwProcessID = %d.", dwProcessID);
TRACE_EXIT();
return TRUE;
}
else
{
TRACE_PRINT1("killProcess_Soft: gracefully kill process, bResult = 0, dwProcessID = %d.", dwProcessID);
TRACE_EXIT();
return FALSE;
}
Expand All @@ -381,3 +382,27 @@ BOOL killInUseProcesses_Soft()
TRACE_EXIT();
return bResult;
}

BOOL killInUseProcesses_Polite()
{
TRACE_ENTER();

BOOL bResult = TRUE;
vector<DWORD> strArrProcessIDs;

strArrProcessIDs = enumProcesses_PID();

for (size_t i = 0; i < strArrProcessIDs.size(); i++)
{
if (!killProcess_Soft(strArrProcessIDs[i]))
{
if (!killProcess(strArrProcessIDs[i]))
{
bResult = FALSE;
}
}
}

TRACE_EXIT();
return bResult;
}
2 changes: 2 additions & 0 deletions packetWin7/NPFInstall/NPFInstall/ProcessUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ tstring getInUseProcesses();
BOOL killInUseProcesses();

BOOL killInUseProcesses_Soft();

BOOL killInUseProcesses_Polite();

0 comments on commit 05aaf42

Please sign in to comment.