#include <windows.h> #include <RestartManager.h> #include <stdio.h> #pragma comment(lib, "Rstrtmgr.lib") int __cdecl wmain(int argc, WCHAR **argv) { DWORD dwSession; PCWSTR pszFile = _T("D:\\R00RR0162232162_2023070523_MACHINE-ALARM.csv"); HANDLE hFile = CreateFile(pszFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL); auto thisProcID = GetProcessId(GetCurrentProcess()); WCHAR szSessionKey[CCH_RM_SESSION_KEY + 1] = { 0 }; DWORD dwError = RmStartSession(&dwSession, 0, szSessionKey); wprintf(L"RmStartSession returned %d\n", dwError); if (dwError == ERROR_SUCCESS) { dwError = RmRegisterResources(dwSession, 1, &pszFile, 0, NULL, 0, NULL); wprintf(L"RmRegisterResources(%ls) returned %d\n", pszFile, dwError); if (dwError == ERROR_SUCCESS) { DWORD dwReason; UINT i; UINT nProcInfoNeeded; UINT nProcInfo = 10; RM_PROCESS_INFO rgpi[10]; dwError = RmGetList(dwSession, &nProcInfoNeeded, &nProcInfo, rgpi, &dwReason); wprintf(L"RmGetList returned %d\n", dwError); if (dwError == ERROR_SUCCESS) { wprintf(L"RmGetList returned %d infos (%d needed)\n", nProcInfo, nProcInfoNeeded); for (i = 0; i < nProcInfo; i++) { wprintf(L"%d.ApplicationType = %d\n", i, rgpi[i].ApplicationType); wprintf(L"%d.strAppName = %ls\n", i, rgpi[i].strAppName); wprintf(L"%d.Process.dwProcessId = %d\n", i, rgpi[i].Process.dwProcessId); HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_TERMINATE, FALSE, rgpi[i].Process.dwProcessId); if (hProcess) { FILETIME ftCreate, ftExit, ftKernel, ftUser; if (GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser) && CompareFileTime(&rgpi[i].Process.ProcessStartTime, &ftCreate) == 0) { WCHAR sz[MAX_PATH]; DWORD cch = MAX_PATH; if (QueryFullProcessImageNameW(hProcess, 0, sz, &cch) && cch <= MAX_PATH) { wprintf(L" = %ls\n", sz); } } if (thisProcID == rgpi[i].Process.dwProcessId) { wprintf(L"%d.Process.dwProcessId = %d This is me.. I dont kill myself...\n", i, rgpi[i].Process.dwProcessId); } else { if (TerminateProcess(hProcess, 0)) { wprintf(L"%d.Process.dwProcessId = %d TerminateProcess ok\n", i, rgpi[i].Process.dwProcessId); } else { wprintf(L"%d.Process.dwProcessId = %d TerminateProcess fail\n", i, rgpi[i].Process.dwProcessId); } } CloseHandle(hProcess); } } } } RmEndSession(dwSession); } CloseHandle(hFile); return 0; }
'I ♥ Programming' 카테고리의 다른 글
Windows XP SP3용 그림판 EXE 파일 (mspaint.exe) (0) | 2024.06.20 |
---|---|
c# 디자인 폼 없어졌을때 조치 (0) | 2022.03.04 |
영상 왜곡 형태에 따른 분류 (0) | 2020.09.08 |
Nuget 패키지 관리자 "사용 가능한 패키지 소스" 수동 추가 방법 (0) | 2020.03.16 |
opencv cv::Mat 클래스 초기화 방법 및 사용 방법 (0) | 2018.05.09 |