Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ElyDotDev/53452042b48a6b6090c0311b879e6e00 to your computer and use it in GitHub Desktop.
Save ElyDotDev/53452042b48a6b6090c0311b879e6e00 to your computer and use it in GitHub Desktop.
windows-kill-library Usage examples. http://projects.allii.ir/list/windows-kill-library/
#include <stdexcept>
#include "windows-kill-library.h"
using WindowsKillLibrary::sendSignal;
using WindowsKillLibrary::SIGNAL_TYPE_CTRL_C;
using WindowsKillLibrary::SIGNAL_TYPE_CTRL_BREAK;
try {
sendSignal(signal_pid, signal_type);
std::cout << "Signal sent successfuly. type: " << signal_type << " | pid: " << signal_pid << "\n";
}
catch (const std::invalid_argument& exception) {
if (strcmp(exception.what(), "ESRCH") == 0) {
std::cout << "Error: Pid dosen't exist." << std::endl;
}
else if(strcmp(exception.what(), "EINVAL") == 0){
std::cout << "Error: Invalid signal type." << std::endl;
}
else {
std::cout << "InvalidArgument: windows-kill-library:" << exception.what() << std::endl;
}
}
catch (const std::system_error& exception) {
std::cout << "SystemError " << exception.code() << ": " << exception.what() << std::endl;
}
catch (const std::runtime_error& exception) {
if (strcmp(exception.what(), "EPERM") == 0) {
std::cout << "Not enough permission to send the signal." << std::endl;
}
else {
std::cout << "RuntimeError: windows-kill-library:" << exception.what() << std::endl;
}
}
catch (const std::exception& exception) {
std::cout << "Error: windows-kill-library:" << exception.what() << std::endl;
}
/// <summary>
/// Sends the signal.
/// </summary>
/// <param name="signal_pid">The signal target process id.</param>
/// <param name="signal_type">The signal type.</param>
void sendSignal(DWORD signal_pid, DWORD signal_type);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment