|
|
|
|
|
/*!
|
|
|
|
|
|
*FileName: SystemTool.cpp
|
|
|
|
|
|
*Author: Pan Yingdong
|
|
|
|
|
|
*Email: bob.pan@hzleaper.com
|
|
|
|
|
|
*Created:2020/6/15 15:28
|
|
|
|
|
|
*Note:ϵͳ<EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><EFBFBD><EFBFBD> ָ<EFBFBD><EFBFBD>
|
|
|
|
|
|
*/
|
|
|
|
|
|
#include "SystemTool.h"
|
|
|
|
|
|
#include <process.h>
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
bool SystemTool::SystemShutDown(bool bReset)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (bReset == false)
|
|
|
|
|
|
system("shutdown -s -t 00");//<2F>ػ<EFBFBD>
|
|
|
|
|
|
else
|
|
|
|
|
|
system("shutdown -r -t 00");//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string SystemTool::TCHAR2STRING(TCHAR *STR)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
int iLen = WideCharToMultiByte(CP_ACP, 0, STR, -1, NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
char* chRtn = new char[iLen * sizeof(char)];
|
|
|
|
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, STR, -1, chRtn, iLen, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
std::string str(chRtn);
|
|
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SystemTool::isProcessRunning(const char* processName)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool bFound = false;
|
|
|
|
|
|
|
|
|
|
|
|
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
|
|
|
|
|
|
PROCESSENTRY32 pEntry;
|
|
|
|
|
|
pEntry.dwSize = sizeof(pEntry);
|
|
|
|
|
|
BOOL hRes = Process32First(hSnapShot, &pEntry);
|
|
|
|
|
|
while (hRes && !bFound)
|
|
|
|
|
|
{
|
|
|
|
|
|
char* exename = UnicodeToAnsi(pEntry.szExeFile);
|
|
|
|
|
|
QString strExeName(exename);
|
|
|
|
|
|
if (strExeName.compare(processName, Qt::CaseInsensitive) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
bFound = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
delete exename;
|
|
|
|
|
|
|
|
|
|
|
|
hRes = Process32Next(hSnapShot, &pEntry);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return bFound;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemTool::GetProcessPath(DWORD dwProcessID, TCHAR* buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
TCHAR Filename[MAX_PATH];
|
|
|
|
|
|
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessID);
|
|
|
|
|
|
if (hProcess == NULL)return;
|
|
|
|
|
|
HMODULE hModule;
|
|
|
|
|
|
DWORD cbNeeded;
|
|
|
|
|
|
if (EnumProcessModules(hProcess, &hModule, sizeof(hModule), &cbNeeded))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (GetModuleFileNameEx(hProcess, hModule, Filename, MAX_PATH)) {
|
|
|
|
|
|
RtlMoveMemory((void*)buffer, Filename, sizeof(TCHAR)*MAX_PATH);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
DWORD size = MAX_PATH;
|
|
|
|
|
|
if (QueryFullProcessImageName(hProcess, 0, Filename, &size)) {
|
|
|
|
|
|
RtlMoveMemory((void*)buffer, Filename, sizeof(TCHAR)*MAX_PATH);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
CloseHandle(hProcess);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<DWORD> SystemTool::getPIDByName(const char* processName)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::vector<DWORD> vecRet;
|
|
|
|
|
|
|
|
|
|
|
|
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
|
|
|
|
|
|
PROCESSENTRY32 pEntry;
|
|
|
|
|
|
pEntry.dwSize = sizeof(pEntry);
|
|
|
|
|
|
BOOL hRes = Process32First(hSnapShot, &pEntry);
|
|
|
|
|
|
while (hRes)
|
|
|
|
|
|
{
|
|
|
|
|
|
char* exename = SystemTool::UnicodeToAnsi(pEntry.szExeFile);
|
|
|
|
|
|
QString strExeName(exename);
|
|
|
|
|
|
if (strExeName.compare(processName, Qt::CaseInsensitive) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
TCHAR appPath[MAX_PATH];
|
|
|
|
|
|
SystemTool::GetProcessPath((DWORD)pEntry.th32ProcessID, appPath);
|
|
|
|
|
|
|
|
|
|
|
|
std::string texts = SystemTool::TCHAR2STRING(appPath);
|
|
|
|
|
|
// QFileInfo appFile(texts.c_str());
|
|
|
|
|
|
// QString strAppPath = appFile.absoluteFilePath();
|
|
|
|
|
|
// if (strAppPath.compare(curAppPath, Qt::CaseInsensitive) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
vecRet.push_back((DWORD)pEntry.th32ProcessID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
delete exename;
|
|
|
|
|
|
hRes = Process32Next(hSnapShot, &pEntry);
|
|
|
|
|
|
}
|
|
|
|
|
|
CloseHandle(hSnapShot);
|
|
|
|
|
|
|
|
|
|
|
|
return vecRet;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemTool::killZombieProcess(const char *curAppName)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::vector<DWORD> PIDs = getPIDByName(curAppName);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < PIDs.size(); ++i)
|
|
|
|
|
|
{
|
|
|
|
|
|
DWORD pid = PIDs.at(i);
|
|
|
|
|
|
|
|
|
|
|
|
// QString strCmd = QString("taskkill /PID %1 -t -f").arg(pid);
|
|
|
|
|
|
// system(strCmd.toStdString().c_str());
|
|
|
|
|
|
//if (pid != curAppPID)
|
|
|
|
|
|
{
|
|
|
|
|
|
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0, pid);
|
|
|
|
|
|
if (hProcess != NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
TerminateProcess(hProcess, 9);
|
|
|
|
|
|
CloseHandle(hProcess);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString SystemTool::SecondTimeString(quint64 value)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strTime;
|
|
|
|
|
|
int seconds = value % 60;
|
|
|
|
|
|
int minutes = value / 60;
|
|
|
|
|
|
strTime = QString("%1<><31>%2<><32>").arg(minutes).arg(seconds);
|
|
|
|
|
|
if (minutes >= 60) {
|
|
|
|
|
|
minutes = (value / 60) % 60;
|
|
|
|
|
|
int hours = (value / 60) / 60;
|
|
|
|
|
|
strTime = QString("%1ʱ%2<><32>%3<><33>").arg(hours).arg(minutes).arg(seconds);
|
|
|
|
|
|
if (hours >= 24) {
|
|
|
|
|
|
hours = ((value / 60) / 60) % 24;
|
|
|
|
|
|
int day = ((value / 60) / 60) / 24;
|
|
|
|
|
|
strTime = QString("%1<><31>%2ʱ%3<><33>%4<><34>").arg(day).arg(hours).arg(minutes).arg(seconds);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return strTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemTool::ReflashBarIcon()
|
|
|
|
|
|
{
|
|
|
|
|
|
// HWND hShellTrayWnd = FindWindow("Shell_TrayWnd", NULL);
|
|
|
|
|
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>+ʱ<><CAB1><EFBFBD><EFBFBD>
|
|
|
|
|
|
// HWND hTrayNotifyWnd = FindWindowEx(hShellTrayWnd, 0, "TrayNotifyWnd", NULL);
|
|
|
|
|
|
// //<2F><>ͬϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
// HWND hSysPager = FindWindowEx(hTrayNotifyWnd, 0, "SysPager", NULL);
|
|
|
|
|
|
// //<2F><><EFBFBD><EFBFBD>ͼ<EFBFBD>괰<EFBFBD><EAB4B0>
|
|
|
|
|
|
// HWND hToolbarWindow32;
|
|
|
|
|
|
// if (hSysPager)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// hToolbarWindow32 = FindWindowEx(hSysPager, 0, "ToolbarWindow32", NULL);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// hToolbarWindow32 = FindWindowEx(hTrayNotifyWnd, 0, "ToolbarWindow32", NULL);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (hToolbarWindow32)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// RECT r;
|
|
|
|
|
|
// ::GetWindowRect(hToolbarWindow32, &r);
|
|
|
|
|
|
// int width = r.right - r.left;
|
|
|
|
|
|
// int height = r.bottom - r.top;
|
|
|
|
|
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> MOUSEMOVEһ<45>飬<EFBFBD><E9A3AC><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>״̬<D7B4>ᱻ<EFBFBD><E1B1BB><EFBFBD><EFBFBD>
|
|
|
|
|
|
// for (int x = 1; x < width; x++)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ::SendMessage(hToolbarWindow32, WM_MOUSEMOVE, 0, MAKELPARAM(x, height / 2));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|