92 lines
2.1 KiB
C++
92 lines
2.1 KiB
C++
// stdafx.cpp : 표준 포함 파일만 들어 있는 소스 파일입니다.
|
|
// SunUpdateAgent.pch는 미리 컴파일된 헤더가 됩니다.
|
|
// stdafx.obj에는 미리 컴파일된 형식 정보가 포함됩니다.
|
|
|
|
#include "stdafx.h"
|
|
|
|
// TODO: 필요한 추가 헤더는
|
|
// 이 파일이 아닌 STDAFX.H에서 참조합니다.
|
|
|
|
CBasicLog* g_pLog = NULL;
|
|
|
|
VOID MessageOut( TCHAR* pszMsg... )
|
|
{
|
|
char strBuffer[256];
|
|
|
|
va_list args;
|
|
va_start(args, pszMsg);
|
|
_vsnprintf( strBuffer, 256, pszMsg, args );
|
|
va_end(args);
|
|
|
|
printf("%s\n", strBuffer); //임시로.. 썬로그가 생성되지 않았으면 화면에 출력시켜라...
|
|
|
|
if(g_pLog)
|
|
g_pLog->InsertMessage( strBuffer );
|
|
}
|
|
|
|
|
|
//현재 컴퓨터에 업데이트하고 있는 프로그램이 실행중인지 체크.
|
|
//실행중인 프로그램이 하나라도 있으면 TRUE리턴
|
|
//아니면 FASLE를 리턴..
|
|
BOOL CheckLiveProcess( TCHAR* pszProcess, OUT DWORD& dwProID, DWORD dwExceptProcID )
|
|
{
|
|
if( !pszProcess || strcmp( pszProcess, "" ) == 0 )
|
|
return FALSE;
|
|
|
|
// 프로세스 체크 런쳐나 게임 클라이언트가 실행중인지 체크한다
|
|
HANDLE hSnapShot = NULL;
|
|
PROCESSENTRY32 pEntry = {0};
|
|
|
|
//Get the snapshot of the system
|
|
hSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
|
|
if( hSnapShot == INVALID_HANDLE_VALUE )
|
|
return FALSE;
|
|
|
|
pEntry.dwSize = sizeof(pEntry);
|
|
|
|
//Get first process
|
|
if( Process32First(hSnapShot, &pEntry) )
|
|
{
|
|
//Iterate thru all processes
|
|
DWORD dwMySelfPID = GetCurrentProcessId();
|
|
|
|
do
|
|
{
|
|
//자기 자신은 넘어간다. 제외할 프로세서 id도 넘어간다.
|
|
if( dwMySelfPID == pEntry.th32ProcessID || dwExceptProcID == pEntry.th32ProcessID )
|
|
continue;
|
|
|
|
// 실행 중인지 체크하도록 한다.
|
|
if( strcmp( pEntry.szExeFile, pszProcess ) == 0 ) //현재 같은 프로그램이 실행중이라면..
|
|
{
|
|
dwProID = pEntry.th32ProcessID;
|
|
CloseHandle( hSnapShot );
|
|
return TRUE;
|
|
}
|
|
}
|
|
while ( Process32Next(hSnapShot, &pEntry) );
|
|
|
|
}// End While
|
|
|
|
CloseHandle( hSnapShot );
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL ServerForceShutDown( DWORD dwPID )
|
|
{
|
|
HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwPID );
|
|
DWORD dwExitCode = 0;
|
|
if( !GetExitCodeProcess( hProcess, &dwExitCode ) )
|
|
{
|
|
CloseHandle( hProcess );
|
|
return FALSE;
|
|
}
|
|
|
|
if( !TerminateProcess( hProcess, dwExitCode ) )
|
|
{
|
|
CloseHandle( hProcess );
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
} |