Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Get PID ( C# )
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Sun Nov 18, 2007 7:20 pm    Post subject: Get PID ( C# ) Reply with quote

Hello, Im wondering if anyone has an idea of how to get the PID of a running Application?

Ex.

Lunia.exe PID : xxxxx

Im using C#.

Thanks in adv.

_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Nov 18, 2007 7:33 pm    Post subject: Reply with quote

heres it in c++, i assume you can change it. I don't know c#

Code:
void GetPID(void){
  int i;
  bool con;
 PROCESSENTRY32 cProcessEntry32;
  HANDLE cSnapshotHandle;
  cSnapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  cProcessEntry32.dwSize = sizeof(cProcessEntry32);
  con = Process32First(cSnapshotHandle, cProcessEntry32);
  while(con != 0)
{
    MessageBox(hwnd,cProcessEntry32.th32ProcessID, "PID", MB_OK);
    con = Process32Next(cSnapshotHandle, cProcessEntry32);
}
  CloseHandle(cSnapshotHandle);
}


something like that. That will get the PID of ALL running processes. You can explore the PROCESSENTRY32 Structure and figure out how to just get lunia.

_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sun Nov 18, 2007 7:35 pm    Post subject: Reply with quote

Code:

   //using System.Diagnostics
   Process[] myProcesses = Process.GetProcessesByName("lunia");
   foreach(Process myProcess in myProcesses)
   {
       Console.WriteLine("Lunia.exe PID : " + myProcess.Id.ToString());
   }

_________________


Last edited by appalsap on Sun Nov 18, 2007 7:38 pm; edited 2 times in total
Back to top
View user's profile Send private message
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Sun Nov 18, 2007 7:37 pm    Post subject: Reply with quote

appalsap wrote:
Code:

   //using System.Diagnostics
   Process[] myProcesses = Process.GetProcessesByName("lunia");
   foreach(Process myProcess in myProcesses)
   {
       Console.WriteLine("Lunia.exe PID : " + myProcess.Id.ToString());
   }


Thanks, Appalsap.
You always save me when i need to be saved.
Im using this for my Lunia bypass, so this is a definite help.

+Rep.

_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Nov 18, 2007 7:41 pm    Post subject: Reply with quote

Woh...

Since when did Appal know C#?
Back to top
View user's profile Send private message
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Sun Nov 18, 2007 7:45 pm    Post subject: Reply with quote

samuri25404 wrote:
Woh...

Since when did Appal know C#?


Appalsap is a coding god.
She can just look at the issue, and figure the problem, considering, she is a leet as coder Smile.

Also, that code is actually common sense, idk why i wasnt able to google that -_-', and it works GREAT!

-------------------------------------
one more question, Appal, how would i make it display the Message "PID could not be resolved" if there are no LuniaClient.exe running?

Ex.

If LuniaClient.exe not found
{
MessageBox.Show("Pid Could not be resolved");
}

_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Nov 18, 2007 7:50 pm    Post subject: Reply with quote

I learned that little bit (the bit that Appal posted, and yes, I knew it before), from gamesguru's tutorial.

Search for a post by him (using search, or check like the 3rd page of Crack Me's), and get the link to his C# Trainer tutorial.

It really explains a lot, and I'm sure you'll find it helpfull in at least some way.
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sun Nov 18, 2007 7:58 pm    Post subject: Reply with quote

Code:

if (myProcesses.Length == 0)
{
    MessageBox.Show("Pid Could not be resolved");
}

_________________
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Nov 18, 2007 8:03 pm    Post subject: Reply with quote

Code:

private void GetPID(string ProcessName)
{
   Process[] myProcesses = Process.GetProcessesByName(ProcessName);
   if (myProcesses.Length == 0)
   {
       Console.WriteLine("No running application with title " + ProcessName + " found.");
       return;
   }

   foreach(Process p in myProcesses)
   {
       Console.WriteLine(ProcessName + " PID : " + p.Id.ToString());
   }
}


More dynamic. =)
Back to top
View user's profile Send private message
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Sun Nov 18, 2007 8:37 pm    Post subject: Reply with quote

Thanks, works like a charm.
But ONEEE more thing, i thought i had this figured, but, i need to Compare Line 1 in a ini File to a certain string.

Example.
public MyFile = C:\Verify.ini;
If (MyFile.Line1 == "0x00456")
{
MessageBox.show("j00 Failz");
}

Edit :
@ Samuri - Nice!
Ill use that as well(The pat you added in).

_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Nov 18, 2007 9:05 pm    Post subject: Reply with quote

XML files are more compatible with .Net than INI files. Use those.

This is the perfect opportunity to try on my newest image:

Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sun Nov 18, 2007 9:10 pm    Post subject: Reply with quote

Doesn't matter if it's only one line though.

Code:

//using System.IO

FileStream file = null;
StreamReader reader = null;

try
{
    file = new FileStream("c:\\verify.ini", FileMode.Open);
    reader = new StreamReader(file);
    if (reader.ReadLine() == "0x00456")
    {
        MessageBox.show("j00 Failz");
    }
}

finally
{
    reader.Close();
    file.Close();
}

_________________
Back to top
View user's profile Send private message
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Sun Nov 18, 2007 9:14 pm    Post subject: Reply with quote

appalsap wrote:
Doesn't matter if it's only one line though.

Code:

//using System.IO

FileStream file = null;
StreamReader reader = null;

try
{
    file = new FileStream("c:\\verify.ini", FileMode.Open);
    reader = new StreamReader(file);
    if (reader.ReadLine() == "0x00456")
    {
        MessageBox.show("j00 Failz");
    }
}

finally
{
    reader.Close();
    file.Close();
}


Sweet, You are most definitely the most helpfull person on this forum!

Thanks, ive basically gotten everything i need for my Lunia Bypass.

THANKS!

I got spoonfed, thats nice to hear Razz.

_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Nov 18, 2007 9:35 pm    Post subject: Reply with quote

Code:

//using System.IO

FileStream file = null;
StreamReader reader = null;

try
{
    file = new FileStream("c:\\verify.ini", FileMode.Open);
    reader = new StreamReader(file);
    if (reader.ReadLine() == "0x00456")
    {
        MessageBox.show("j00 Failz");
    }
}

finally
{
    reader.Close();
    file.Close();
}
[/quote]

Two things:

1)

Code:

file = new FileStream("c:\\verify.ini", FileMode.Open);


You can do better than that, right?

Code:

file = new FileStream(@"c:\verify.ini", FileMode.Open);


Nobody likes to see a bunch of slashes when they don't need to. =)

2)

I understand what try-catch-finally is, but why use finally?

You could just

Code:

try
{
    file = new FileStream("c:\\verify.ini", FileMode.Open);
    reader = new StreamReader(file);
    if (reader.ReadLine() == "0x00456")
    {
        MessageBox.show("j00 Failz");
    }
}

reader.Close();
file.Close();


Is it supposed to be good practice or something?
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sun Nov 18, 2007 10:04 pm    Post subject: Reply with quote

samuri25404 wrote:
Nobody likes to see a bunch of slashes when they don't need to. =)


that's a matter of style

samuri25404 wrote:
I understand what try-catch-finally is, but why use finally?


because there are many cases where the read could throw an exception (file empty, permission denied etc) and It's good to make sure the file gets closed.

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites