| View previous topic :: View next topic |
| Author |
Message |
ssaccount Master Cheater
Reputation: 0
Joined: 29 Aug 2007 Posts: 391 Location: Finland
|
Posted: Sun Aug 10, 2008 9:13 am Post subject: [C++ Question] Detecting Process |
|
|
Hi. Im using Win32 Console and my problem is that I dont know how to make my program detect a process.
Example:
When the program is running and I open Notepad I want it to detect notepad.exe and if the program detects it, it writes "Notepad.exe found".
_________________
Programming in C++
(Or at least trying to ) |
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Aug 10, 2008 9:37 am Post subject: |
|
|
That detects a window
He wants to detect the process itself.
CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS flag)
Process32First
Process32Next
_tcscmp (for process name check)
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Aug 10, 2008 11:17 am Post subject: |
|
|
_tcscmp only works if he's using Unicode. Otherwise he should use strcmp.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sun Aug 10, 2008 11:25 am Post subject: |
|
|
| oib111 wrote: | | _tcscmp only works if he's using Unicode. Otherwise he should use strcmp. | Isn't wcscmp the unicode one? Tcscmp is the one choosing the right one between ansi and unicode..?
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Aug 10, 2008 12:23 pm Post subject: |
|
|
_tcscmp is the TCHAR macro which will choose the correct function as needed based on compiler options.
Also, you should use _tcsicmp to perform a lowercase compare.
Example:
| Code: | #include <windows.h>
#include <iostream>
#include <tlhelp32.h>
#include <tchar.h>
#include <stdio.h>
BOOL FoundNotepad()
{
PROCESSENTRY32 pe32 = { sizeof( PROCESSENTRY32 ) };
HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hSnapshot == INVALID_HANDLE_VALUE )
return FALSE;
if( Process32First( hSnapshot, &pe32 ) )
{
do{
if( _tcsicmp( pe32.szExeFile, _T("notepad.exe") ) == 0 )
{
CloseHandle( hSnapshot );
return TRUE;
}
}while( Process32Next( hSnapshot, &pe32 ) );
}
CloseHandle( hSnapshot );
return FALSE;
}
int main()
{
_tprintf_s( _T("Scanning for notepad... ") );
while( !FoundNotepad() )
{
// Keep scanning until found...
Sleep( 100 );
}
_tprintf_s( _T("Found!") );
std::cin.sync();
std::cin.ignore();
return 0;
} |
_________________
- Retired. |
|
| Back to top |
|
 |
ssaccount Master Cheater
Reputation: 0
Joined: 29 Aug 2007 Posts: 391 Location: Finland
|
Posted: Sun Aug 10, 2008 8:36 pm Post subject: |
|
|
Thanks for help
_________________
Programming in C++
(Or at least trying to ) |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Aug 11, 2008 2:43 am Post subject: |
|
|
| Wiccaan wrote: | | _tcscmp is the TCHAR macro which will choose the correct function as needed based on compiler options. | Exactly what I meant :)
|
|
| Back to top |
|
 |
|