Join us at IRC!
Your life is ending one minute at a time. If you were to die tomorrow, what would you do today?
Thursday, May 24, 2012
Navigation
Members Online
Total Online: 34
Web Spiders: 14
Guests Online: 29
Members Online: 5

Registered Members: 70180
Newest Member: RAWRFEARME744798
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Get PID of process

ctrl_
Member



Posts: 15
Location:
Joined: 11.02.09
Rank:
Wiseman
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

cyb3rl0rd1867
Member



Posts: 143
Location: U.S
Joined: 07.07.06
Rank:
Hacker Level 1
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

zbert
Member

Posts: 39
Location: Ames, IA USA
Joined: 17.07.08
Rank:
God
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.


Visit my company or check out my programming examples.
nadahx82@yahoo.com http://blog.skeltonnetworks.com
Author

RE: Get PID of process

cyb3rl0rd1867
Member



Posts: 143
Location: U.S
Joined: 07.07.06
Rank:
Hacker Level 1
Posted on 04-04-10 06:48
I don't think he was looking for the parent PID


Author

RE: Get PID of process

ctrl_
Member



Posts: 15
Location:
Joined: 11.02.09
Rank:
Wiseman
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

Posts: 10
Location:
Joined: 29.10.09
Rank:
Mad User
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:
Hacker Level 2
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.


kbcarte.wordpress.com
Author

RE: Get PID of process

fuser
Member



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


he did mention earlier. duh.










Telling modern Internet users to stop whining is like telling them to stop breathing — it seems unrealistic and inhumane. Paul Lutus

catinthecpu@hotmail.com
Author

RE: Get PID of process

j4m32
Member

Posts: 81
Location:
Joined: 01.05.10
Rank:
God
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++):


(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,
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.