WTF with this if( many strcmp() ) not working

What is the problem with this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
PROCESSENTRY32 pEntry;
   HANDLE pSnap;
   
   pSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
   char ExeName[MAX_PATH] = "System";
   char ExeName1[MAX_PATH] = "smss.exe";
   char ExeName2[MAX_PATH] = "csrss.exe";
   char ExeName3[MAX_PATH] = "winlogon.exe";
   char ExeName4[MAX_PATH] = "services.exe";
   char ExeName5[MAX_PATH] = "lsass.exe";
   char ExeName6[MAX_PATH] = "svchost.exe";
   char ExeName7[MAX_PATH] = "spoolsv.exe";

   while(Process32Next(pSnap, &pEntry)) 
   {
   int pid = pEntry.th32ProcessID;
   char *szExE = pEntry.szExeFile;
   

   if(strcmp(ExeName, szExE) != 0)// This works fine (only if 1 strcmp)
     {
//More code here
}

but this:
if(strcmp(ExeName, szExE) != 0 || strcmp(ExeName1, szExE) != 0)
by each ExeNameX... it don't work, tried also with (), same.
What is the correct method? I'm lost in code
Last edited on
There's nothing "wrong" with it. It will do what you program it to do. What are you trying to do? What does it do that you don't want it to, or what does it not do that you would like it to?
Sorry to say but it's not working (strange but im sure) if there is more than 1 strcmp() in the if().

I'm trying to open processes except those in ExeNameX, with 1 by one will work, with more won't work. Weird shit...

Can anyone help? Any hint welcomed, it's a bit urgent. Thnx in advance

=====================================================================
UPDATE: I got it working now by doing this:
1
2
3
4
5
6
7
if(!strcmp(ExeName, szExE) || !strcmp(ExeName1, szExE) || .....)
{
}
else
{
//More code here
}


But still don't understand why... ohh i know, I'm a fucking noob, damn.
Last edited on
the strcmp() exists approximately since the beginning of C and is used by millions of programmers. Yes, it's guaranteed to work.

It may not produce the expected result. So you have to tell us what this expected result is, i.e. what it is that makes you think it doesn't work
How about this? Does this work?
if((strcmp(ExeName, szExE) != 0) || (strcmp(ExeName1, szExE) != 0))
Topic archived. No new replies allowed.