Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Detect Determine Application Program Process Launched Ran Spawned Parent Child Calling Current Module Name WinExeName ZwQueryInformationProcess GetCurrentProcess GetCurrentProcessId
GETPARENTPROCID.WBT - Get parent process info
; GetParentProcId.wbt ; 32-bit ; ; This script makes use of one of the Win32 Kernel API functions to obtain the current process' parent process id number. ; The parent process' id can then be used to get information about the parent process. #DefineFunction udfGetMyParentProcId() ; 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) nMyParentProcId = BinaryPeek4(hProcInfoBuf,20) ; Sanity check - get our own process id by another method. nMyProcId2 = DllCall('KERNEL32.DLL',long:'GetCurrentProcessId') hProcInfoBuf = BinaryFree(hProcInfoBuf) Return nMyParentProcId #EndFunction #DefineFunction IsMyParentAConsole() MyParentProcId = udfGetMyParentProcId() MyParentMods = tListMod(MyParentProcId,1) ConsoleModName = StrLower(StrCat(DirWindows(1),'CMD.EXE')) bResult = @FALSE nCount = ItemCount(MyParentMods,@TAB) For nIndex = 1 To nCount ModName = StrLower(ItemExtract(nIndex,MyParentMods,@TAB)) If (ModName == ConsoleModName) bResult = @TRUE Break EndIf Next Return bResult #EndFunction AddExtender('wwprc44I.dll') Title01 = 'Get Parent Process Id' Result = IsMyParentAConsole() Message(Title01,StrCat('Is my parent process a console? Result = ',Result)) Exit
Article ID: W17026
File Created: 2013:04:01:09:17:06
Last Updated: 2013:04:01:09:17:06