Follow us on Twitter!
Capitalism is an Island of wealth in a sea of poverty
Friday, April 25, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 19
Guests Online: 17
Members Online: 2

Registered Members: 82909
Newest Member: awais
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Get PID of process


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 02-04-10 04:15
I'm having problems finding a Windows API that I can use in python ctypes that can return the PID of a service/process if you only know the name of the process. Anyone got any ideas about how I can work around this problem?


Author

RE: Get PID of process


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 02-04-10 04:39
Use FindWindow to get the handle and GetWindowThreadProcessId() to get the pid using the handle.


Author

RE: Get PID of process


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-04-10 06:34
Here's a great example I found through Google: http://stackoverflow.com/questions/185254/how-can-a-win32-process-get-the-pid-of-its-parent.


Author

RE: Get PID of process


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-04-10 06:48
I don't think he was looking for the parent PID


Author

RE: Get PID of process


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-04-10 17:49
cyb3rl0rd1867 wrote:
Use FindWindow to get the handle and GetWindowThreadProcessId() to get the pid using the handle.
Not exactly what I was looking for but it helps. This method only worked for me when the process had a open window, not if it was running in the backgroud. I'm going to look into this some more next weekend when I got some spare time.


Author

RE: Get PID of process

mike1990
Member

Your avatar

Posts: 10
Location:
Joined: 29.10.09
Rank:
Guest
Posted on 09-05-10 04:28
What programming language you coding in?
Author

RE: Get PID of process

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Moderate
Posted on 09-05-10 07:04
Here and this code will get you started. The book that the code is for is pretty good too. Gray Hat Python by Justin Seitz.


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: Get PID of process

fuser
Member



Posts: 960
Location: in front of a computer (duh)
Joined: 05.04.07
Rank:
Mad User
Posted on 09-05-10 16:33
mike1990 wrote:
What programming language you coding in?


he did mention earlier. duh.


img.userbarz.com/51/10006.png
img.userbarz.com/146/29144.gif
img.userbarz.com/99/19602.jpg
img.userbarz.com/4/600.png
img.userbarz.com/45/8814.gif
img360.imageshack.us/img360/9231/bfbarlr0.jpg
[url=http://userbarz.com/][img]ht
catinthecpu@hotmail.com
Author

RE: Get PID of process

j4m32
Member

Your avatar

Posts: 81
Location:
Joined: 01.05.10
Rank:
Newbie
Posted on 10-05-10 19:07
Sorry, first post ever here and I don't have any Python specific knowledge

I'll try and help with some guide line source for C++...
with the Win API usually you can enumerate the process list and filter by image name and then find the PID using something like this (sorry it's C++):

Code

(dword) PID;

(char) szExe[256]; //probably fine as a string in Python?

(Handle) = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); //This takes a snapshot of the processes at the time of calling the function

(PROCESSENTRY32) procEntry; //This is the structure the snapshots are then stored in

procEntry.dwSize = sizeof( PROCESSENTRY32 ); //just a safety precaution in allocating memory (from what I remember)

Process32First(Handle, &procEntry); //get an entry to start off

//keep going through them until the end of the list
while(Process32Next(Handle, &procEntry) != false){
//...
//code here to do stuff to match the process you're after, probably matching by a specific image name?

szExe = procEntry.szExeFile;
if(strcmp(szExe,"somename.exe") == 0){ //probably ok to just strait compare the strings with == like in PHP?

PID = procEntry.th32ProcessID;

}

//...
}





Sorry I can't really think of anything more general in a code layout...

I hope that helps somehow in getting a PID for your application in Python - without there being an active main window loaded with a handle.

Jim,