Using "pending restart" as a condition in action script

(imported topic written by SystemAdmin)

I want to ensure that a device is not “pending restart” prior to installing a software package, the application developer has made this a requirement. I was thinking that I could put a condition in the action script that would restart the device if needed and simply setup my action to retry.

This statement seems to work:

if { (exists (key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager" of registry) whose (exists value "PendingFileRenameOperations"  of it )) }
    restart 10
else
    ...
endif

but this does not, it always evaluates to true:

if { pending restart }
    restart 10
else
    ...
endif

Should I be able to do this? I know there would be some issues with devices always showing pendng restart and may consider some additional relevance to take that into account, but I just wanted to demonstrate the most basic situation. Is there a better way of designing this altogether?

(imported comment written by SystemAdmin)

You could use a baseline. You could use the “Restart Needed” action as the first part of the baseline, and then only move on to the installation once that has been satisfied.