Just to close the loop on this, I now have this with a few fixlets in production, and there is at least one additional edge case to consider.
As noted earlier, this works in client 9.1 or later where pid of service "name"
was added.
delete __createfile
createfile until EOF
REM Put real installer commands here
REM 'cmd /K' is a good way to test the timeout functionality
EOF
delete Installer.cmd
move __createfile Installer.cmd
parameter "StartTime"="{now}"
runhidden cmd.exe /c "Installer.cmd"
pause while {exists processes whose (name of it = "cmd.exe" and ppid of it = pid of service "BESClient") AND (now - (parameter "StartTime" as time) < 5 * minute)}
if {exists processes whose (name of it = "cmd.exe" and ppid of it = pid of service "BESClient")}
parameter "KillingItDueToTimeout"="True"
waithidden taskkill.exe {concatenation of ("/PID " & it as string & " ") of ids of processes whose (name of it = "cmd.exe" and ppid of it = pid of service "BESClient")} /T /F
else
parameter "KillingItDueToTimeout"="False"
endif
This has the advantage that if there is more than one “cmd.exe” process spawned off by the BESClient, it will kill each of them; otherwise it would have given a relevance substitution error due to multiple results for the PID check. I also use the “KillingItDueToTimeout” parameter just to put an entry in the BES Client log.