|
@@ -2,7 +2,8 @@
|
|
|
|
|
|
// This must be included before many other Windows headers.
|
|
|
#include <windows.h>
|
|
|
-
|
|
|
+#include <tlhelp32.h>
|
|
|
+#include <string>
|
|
|
// For getPlatformVersion; remove unless needed for your plugin implementation.
|
|
|
#include <VersionHelpers.h>
|
|
|
|
|
@@ -53,6 +54,54 @@ void HideConsole() {
|
|
|
ShowWindow(consoleWindow, SW_HIDE);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+bool IsProcessRunning(const std::wstring& processName) {
|
|
|
+ bool isRunning = false;
|
|
|
+ HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
+
|
|
|
+ if (hSnapshot != INVALID_HANDLE_VALUE) {
|
|
|
+ PROCESSENTRY32 pe32;
|
|
|
+ pe32.dwSize = sizeof(PROCESSENTRY32);
|
|
|
+
|
|
|
+ if (Process32First(hSnapshot, &pe32)) {
|
|
|
+ do {
|
|
|
+ if (processName == pe32.szExeFile) {
|
|
|
+ isRunning = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while (Process32Next(hSnapshot, &pe32));
|
|
|
+ }
|
|
|
+
|
|
|
+ CloseHandle(hSnapshot);
|
|
|
+ }
|
|
|
+
|
|
|
+ return isRunning;
|
|
|
+}
|
|
|
+void KillProcess(const std::wstring& processName) {
|
|
|
+ HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
+
|
|
|
+ if (hSnapshot != INVALID_HANDLE_VALUE) {
|
|
|
+ PROCESSENTRY32 pe32;
|
|
|
+ pe32.dwSize = sizeof(PROCESSENTRY32);
|
|
|
+
|
|
|
+ if (Process32First(hSnapshot, &pe32)) {
|
|
|
+ do {
|
|
|
+ if (processName == pe32.szExeFile) {
|
|
|
+ HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID);
|
|
|
+ if (hProcess != NULL) {
|
|
|
+ TerminateProcess(hProcess, 0);
|
|
|
+ CloseHandle(hProcess);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } while (Process32Next(hSnapshot, &pe32));
|
|
|
+ }
|
|
|
+
|
|
|
+ CloseHandle(hSnapshot);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
namespace wl_base_help {
|
|
|
|
|
|
// static
|
|
@@ -81,7 +130,20 @@ void WlBaseHelpPlugin::HandleMethodCall(
|
|
|
const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
|
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
|
|
|
|
|
- if (method_call.method_name().compare("showConsole") == 0) {
|
|
|
+
|
|
|
+ if (method_call.method_name().compare("isProcessRunning") == 0) {
|
|
|
+ const auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
|
|
|
+ auto processName = std::get<std::string>(arguments->find(flutter::EncodableValue("processName"))->second);
|
|
|
+ bool isRunning = IsProcessRunning(std::wstring(processName.begin(), processName.end()));
|
|
|
+ result->Success(flutter::EncodableValue(isRunning));
|
|
|
+ }
|
|
|
+ else if (method_call.method_name().compare("killProcess") == 0) {
|
|
|
+ const auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
|
|
|
+ auto processName = std::get<std::string>(arguments->find(flutter::EncodableValue("processName"))->second);
|
|
|
+ KillProcess(std::wstring(processName.begin(), processName.end()));
|
|
|
+ result->Success();
|
|
|
+ }
|
|
|
+ else if (method_call.method_name().compare("showConsole") == 0) {
|
|
|
ShowConsole();
|
|
|
result->Success();
|
|
|
}
|