I want to do it by programming/scripting. Can you please point out which function to use for this task?
There is no JSAPI function for that task - only the doc.removeScript() method, which doesn't affect code abstracted from the document level (code on buttons, page actions, rich media, etc.)
You can execute a preflight profile using the preflight() method of the
Use Preflight.getProfileByName() to retrieve the PreflightProfile object you
want to execute.