| View previous topic :: View next topic |
| Author |
Message |
Morph.C Cheater
Reputation: 0
Joined: 15 Aug 2009 Posts: 29
|
Posted: Thu Aug 27, 2009 5:41 pm Post subject: Convert This Code to C# |
|
|
Hello everyone, I have a problem, I have spent almost all my code the a dll injector, from Delphi to C#, but the problem is the "GetPid" Function, I not can convert it, someone could do me the please of converting the code to C#?
This is The Code:
| Code: | function GetPID(ProcessName: String): Cardinal;
begin
Result:=0;
SnapShotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
MyProcessEntry.dwSize:=SizeOf(TProcessEntry32);
if not (Process32First(SnapShotHandle, MyProcessEntry)) then
Exit;
repeat
if (ProcessName = MyProcessEntry.szExeFile) then
Result := MyProcessEntry.th32ProcessID;
until not (Process32Next(SnapShotHandle, MyProcessEntry));
end; |
Thanks In Advance. And. if you not want, don't tell me stupid words.
|
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Thu Aug 27, 2009 8:03 pm Post subject: |
|
|
| Code: | public int GetPID(String ProcessName)
{
return Process.GetProcessesByName(ProcessName)[0].Id;
} |
or
| Code: | public int GetPID(String ProcessName)
{
return Process.GetProcessesByName(ProcessName).Id;
} |
Not tested, but should work.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
|
| Back to top |
|
 |
Morph.C Cheater
Reputation: 0
Joined: 15 Aug 2009 Posts: 29
|
Posted: Thu Aug 27, 2009 10:26 pm Post subject: |
|
|
Oh man, not works. i create a new thread, with my full code to see if anyone can help me.
Until then thanks for trying to help.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Aug 27, 2009 11:10 pm Post subject: |
|
|
| Code: | | Process[] proc = Process.GetProcessesByName("process name"); //don't add the .exe part! |
|
|
| Back to top |
|
 |
Morph.C Cheater
Reputation: 0
Joined: 15 Aug 2009 Posts: 29
|
Posted: Thu Aug 27, 2009 11:45 pm Post subject: |
|
|
| slovach wrote: | | Code: | | Process[] proc = Process.GetProcessesByName("process name"); //don't add the .exe part! |
|
Man!!, this is the problem, this function any select the process with extentions ".exe" and i want to atach a process with a extention ".gme" you understand me? ¬¬..
Sorry but this code not can, see my next post maybe you can Fix the problem! Thanks for you time.
|
|
| Back to top |
|
 |
FullyAwesome I post too much
Reputation: 0
Joined: 05 Apr 2007 Posts: 4438 Location: Land Down Under
|
Posted: Fri Aug 28, 2009 12:56 am Post subject: |
|
|
| Morph.C wrote: | | slovach wrote: | | Code: | | Process[] proc = Process.GetProcessesByName("process name"); //don't add the .exe part! |
|
Man!!, this is the problem, this function any select the process with extentions ".exe" and i want to atach a process with a extention ".gme" you understand me? ¬¬..
Sorry but this code not can, see my next post maybe you can Fix the problem! Thanks for you time. |
i've got no idea what the fuck you're trying to see, but you can always edit the string and remove everything after the '.' .
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Aug 28, 2009 12:57 am Post subject: |
|
|
| Morph.C wrote: | | slovach wrote: | | Code: | | Process[] proc = Process.GetProcessesByName("process name"); //don't add the .exe part! |
|
Man!!, this is the problem, this function any select the process with extentions ".exe" and i want to atach a process with a extention ".gme" you understand me? ¬¬..
Sorry but this code not can, see my next post maybe you can Fix the problem! Thanks for you time. |
It returns an array of processes that match that name, if multiple processes share the same name, it will return them all.
If that .gme thing is an actual process, it will probably come up fine.
You can also try using the GetProcesses method to return all running processes. Did you even read the link I posted?
|
|
| Back to top |
|
 |
|