Tech Tip: Getting the PID of 4D on Windows
PRODUCT: 4D | VERSION: 16 | PLATFORM: Win
Published On: June 21, 2018
Sometimes it may be usefule to obtain the PID of the 4D application. This can be accomplished fairly easily on Windows by utilizing PowerShell.
In PowerShell, the PID of the parent process can be obtained like this:
(gwmi win32_process | ? processid -eq $PID).parentprocessid |
When calling PowerShell from 4D, 4D becomes the Parent Process. Therefore, the 4D process can be obtained using the following 4D code:
C_LONGINT($0) C_BLOB($blob) C_TEXT($cmd;$in;$out;$err;$script;$pid) $script:="(gwmi win32_process | ? processid -eq $PID).parentprocessid" $cmd:="powershell -NoLogo -Command "+$script SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true") LAUNCH EXTERNAL PROCESS($cmd;$in;$out;$err) $pid:=Replace string($out;Char(Line feed);"") $pid:=Replace string($pid;Char(Carriage return);"") $0:=num($pid) |
If the code above was saved in a project method named get4Dpid it could be used like this:
ALERT(STRING(get4Dpid)) |