检查本功能是否在Excel中运行

 BOOL g_bParentIsNotEXCEL_EXE = FALSE;
BOOL isNotEXCEL_EXE( DWORD dwProcessID )
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32; // Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
return( FALSE );
} // Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 ); // Retrieve information about the first process, and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
CloseHandle( hProcessSnap ); // Must clean up the snapshot object!
return( FALSE );
} // Now walk the snapshot of processes, and display information about each process in turn
do
{ if( pe32.th32ProcessID == dwProcessID )
{
CString strExeFile = pe32.szExeFile;
//AfxMessageBox( strExeFile);
strExeFile.MakeUpper();
if( strExeFile != _T("EXCEL.EXE") && strExeFile != _T("MATLAB.EXE"))
{
CloseHandle( hProcessSnap ); // Must clean up the snapshot object!
return TRUE;
}
break;
}
} while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap ); // Must clean up the snapshot object!
return FALSE;
}
     HMODULE hModule = LoadLibrary(L"NTdll.dll");
if (hModule)
{
NTSTATUS (__stdcall *NtQueryInformationProcess) (
IN HANDLE ProcessHandle,
IN PROCESSINFOCLASS ProcessInformationClass,
OUT PVOID ProcessInformation,
IN ULONG ProcessInformationLength,
OUT PULONG ReturnLength OPTIONAL
); (FARPROC &)NtQueryInformationProcess = GetProcAddress(hModule, "NtQueryInformationProcess");
if (NtQueryInformationProcess)
{
DWORD dwProcessID = GetCurrentProcessId(); HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,dwProcessID);
if( NULL != hProcess )
{
LONG status;
PROCESS_BASIC_INFORMATION pbi;
status = NtQueryInformationProcess( hProcess,ProcessBasicInformation,(PVOID)&pbi,sizeof(PROCESS_BASIC_INFORMATION),NULL );
if (!status)
{
g_bParentIsNotEXCEL_EXE = isNotEXCEL_EXE( ( DWORD )pbi.Reserved3 );
}
}
}
}
上一篇:ZOJ 3811 Untrusted Patrol


下一篇:蓝桥网试题 java 基础练习 分解质因数