WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Get Process ID Thread

Keywords:  GetWindowThreadProcessId  GetCurrentProcessId

Simple GetCurrentProcessId

ThisPid = DllCall("kernel32.dll", long:"GetCurrentProcessId")


GetCurrentProcessId UDF

#DefineFunction GetCurrentProcessId()
   ;DWORD WINAPI GetCurrentProcessId(void);
   Return DllCall(DirWindows(1):"kernel32.dll",long:"GetCurrentProcessId")
#EndFunction
pid=GetCurrentProcessId()
Message("Process ID",pid)


GetWindowThreadProcessId UDF


#DefineFunction GetProcessID(h)
   ;DWORD GetWindowThreadProcessId(
   ;  HWND hWnd,             // handle to window
   ;  LPDWORD lpdwProcessId  // process identifier
   ;)
   bb=BinaryAlloc(4)
   BinaryEodSet(bb,4)
   dllname=StrCat(DirWindows(1),"user32.dll")
   DllCall(dllname,long:"GetWindowThreadProcessId",long:h,lpbinary:bb)
   p=BinaryPeek4(bb,0)
   BinaryFree(bb)
   Return (p)
#EndFunction
hwnd=DllHwnd("")  ; window title goes in here
pid=GetProcessID(hwnd)
Message(hwnd,pid)

Article ID:   W15164
File Created: 2013:02:22:14:51:16
Last Updated: 2013:02:22:14:51:16