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.

Get Current Process ID


; This script makes use of one of the Win32 Kernel API functions to obtain the current process' process id number.
#DefineFunction udfGetMyProcId()
   ; Get a pseudo-handle to our own process.
   hMyProc = DllCall('KERNEL32.DLL',long:'GetCurrentProcess')
   ; Set up the input parameters for ZwQueryInformationProcess().
   nProcInfoBufSize = 6 * 4
   hProcInfoBuf = BinaryAlloc(nProcInfoBufSize)
   ProcessBasicInformation = 0
   Result = DllCall('NTDLL.DLL',long:'ZwQueryInformationProcess',long:hMyProc,long:ProcessBasicInformation,lpbinary:hProcInfoBuf,long:nProcInfoBufSize,lpnull)
   BinaryEodSet(hProcInfoBuf,nProcInfoBufSize)
   nMyProcId = BinaryPeek4(hProcInfoBuf,16)
   hProcInfoBuf = BinaryFree(hProcInfoBuf)
   Return nMyProcId
#EndFunction

procid = udfGetMyProcId()
Message("Current Process ID",procid)
Exit

Article ID:   W17421
File Created: 2008:04:10:15:09:42
Last Updated: 2008:04:10:15:09:42