|
|
@ -26,7 +26,7 @@ |
|
|
#include <TlHelp32.h> |
|
|
#include <TlHelp32.h> |
|
|
//Create Shortscuts on Runtime
|
|
|
//Create Shortscuts on Runtime
|
|
|
#include "Windows/AllowWindowsPlatformTypes.h" |
|
|
#include "Windows/AllowWindowsPlatformTypes.h" |
|
|
#include <Windows.h> |
|
|
#include "Windows/WindowsHWrapper.h" |
|
|
#include <shobjidl.h> |
|
|
#include <shobjidl.h> |
|
|
#include <shlguid.h> |
|
|
#include <shlguid.h> |
|
|
#include "Windows/HideWindowsPlatformTypes.h" |
|
|
#include "Windows/HideWindowsPlatformTypes.h" |
|
|
@ -69,42 +69,54 @@ void UBToolsBPLibrary::TerminateProc(FTheProcHandle procHandle) |
|
|
|
|
|
|
|
|
bool UBToolsBPLibrary::KillProcessByName(FString Name) |
|
|
bool UBToolsBPLibrary::KillProcessByName(FString Name) |
|
|
{ |
|
|
{ |
|
|
bool killedProg = false; |
|
|
|
|
|
#if PLATFORM_WINDOWS |
|
|
#if PLATFORM_WINDOWS |
|
|
|
|
|
bool bKilledProcess = false; |
|
|
|
|
|
|
|
|
|
|
|
if (Name.IsEmpty()) |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
FString ProcNameWithExtension = Name; |
|
|
FString ProcNameWithExtension = Name; |
|
|
if (ProcNameWithExtension.Find(TEXT(".exe"), ESearchCase::IgnoreCase, ESearchDir::FromEnd) == INDEX_NONE) |
|
|
if (!ProcNameWithExtension.EndsWith(TEXT(".exe"), ESearchCase::IgnoreCase)) |
|
|
{ |
|
|
{ |
|
|
ProcNameWithExtension += TEXT(".exe"); |
|
|
ProcNameWithExtension += TEXT(".exe"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const HANDLE Snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
|
|
HANDLE SnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
|
|
if (Snapshot == INVALID_HANDLE_VALUE) |
|
|
if (SnapShot != INVALID_HANDLE_VALUE) |
|
|
|
|
|
{ |
|
|
{ |
|
|
PROCESSENTRY32 Entry; |
|
|
return false; |
|
|
Entry.dwSize = sizeof(PROCESSENTRY32); |
|
|
} |
|
|
|
|
|
|
|
|
if (::Process32First(SnapShot, &Entry)) //Kill all progamms with there is more than one
|
|
|
PROCESSENTRY32 Entry = {}; |
|
|
|
|
|
Entry.dwSize = sizeof(PROCESSENTRY32); |
|
|
|
|
|
|
|
|
|
|
|
if (::Process32First(Snapshot, &Entry)) |
|
|
|
|
|
{ |
|
|
|
|
|
do |
|
|
{ |
|
|
{ |
|
|
do |
|
|
if (FCString::Stricmp(*ProcNameWithExtension, Entry.szExeFile) == 0) |
|
|
{ |
|
|
{ |
|
|
if (FCString::Stricmp(*ProcNameWithExtension, Entry.szExeFile) == 0) |
|
|
const HANDLE ProcessHandle = ::OpenProcess(PROCESS_TERMINATE, false, Entry.th32ProcessID); |
|
|
|
|
|
if (ProcessHandle) |
|
|
{ |
|
|
{ |
|
|
HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, Entry.th32ProcessID); |
|
|
if (::TerminateProcess(ProcessHandle, 0)) |
|
|
TerminateProcess(processHandle, 0); |
|
|
{ |
|
|
//FPlatformProcess::TerminateProc(SnapShot, true);
|
|
|
bKilledProcess = true; |
|
|
killedProg = true; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
::CloseHandle(ProcessHandle); |
|
|
} |
|
|
} |
|
|
} while (::Process32Next(SnapShot, &Entry)); |
|
|
} |
|
|
} |
|
|
} while (::Process32Next(Snapshot, &Entry)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
::CloseHandle(SnapShot); |
|
|
::CloseHandle(Snapshot); |
|
|
|
|
|
return bKilledProcess; |
|
|
|
|
|
#else |
|
|
|
|
|
return false; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
return killedProg; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int UBToolsBPLibrary::KillProcessesByPath(FString Dir) |
|
|
int UBToolsBPLibrary::KillProcessesByPath(FString Dir) |
|
|
@ -169,36 +181,45 @@ bool UBToolsBPLibrary::IsProgramRunningByName(FString ProcName) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
#if PLATFORM_WINDOWS |
|
|
#if PLATFORM_WINDOWS |
|
|
|
|
|
if (ProcName.IsEmpty()) |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
FString ProcNameWithExtension = ProcName; |
|
|
FString ProcNameWithExtension = ProcName; |
|
|
if (ProcNameWithExtension.Find(TEXT(".exe"), ESearchCase::IgnoreCase, ESearchDir::FromEnd) == INDEX_NONE) |
|
|
if (!ProcNameWithExtension.EndsWith(TEXT(".exe"), ESearchCase::IgnoreCase)) |
|
|
{ |
|
|
{ |
|
|
ProcNameWithExtension += TEXT(".exe"); |
|
|
ProcNameWithExtension += TEXT(".exe"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
HANDLE SnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
|
|
const HANDLE Snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
|
|
if (SnapShot != INVALID_HANDLE_VALUE) |
|
|
if (Snapshot == INVALID_HANDLE_VALUE) |
|
|
{ |
|
|
{ |
|
|
PROCESSENTRY32 Entry; |
|
|
return false; |
|
|
Entry.dwSize = sizeof(PROCESSENTRY32); |
|
|
} |
|
|
|
|
|
|
|
|
if (::Process32First(SnapShot, &Entry)) |
|
|
bool bIsRunning = false; |
|
|
|
|
|
|
|
|
|
|
|
PROCESSENTRY32 Entry = {}; |
|
|
|
|
|
Entry.dwSize = sizeof(PROCESSENTRY32); |
|
|
|
|
|
|
|
|
|
|
|
if (::Process32First(Snapshot, &Entry)) |
|
|
|
|
|
{ |
|
|
|
|
|
do |
|
|
{ |
|
|
{ |
|
|
do |
|
|
if (FCString::Stricmp(*ProcNameWithExtension, Entry.szExeFile) == 0) |
|
|
{ |
|
|
{ |
|
|
if (FCString::Stricmp(*ProcNameWithExtension, Entry.szExeFile) == 0) |
|
|
bIsRunning = true; |
|
|
{ |
|
|
break; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
} while (::Process32Next(Snapshot, &Entry)); |
|
|
} while (::Process32Next(SnapShot, &Entry)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
::CloseHandle(SnapShot); |
|
|
::CloseHandle(Snapshot); |
|
|
|
|
|
return bIsRunning; |
|
|
#endif |
|
|
#else |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
|
|
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
FString UBToolsBPLibrary::GetLocalAppDataPath() |
|
|
FString UBToolsBPLibrary::GetLocalAppDataPath() |
|
|
|