For an automated setup build that generates the setup for an application which uses Microsoft SQL Server, I am currently evaluating whether the following is possible:
<You should be able to do it in managed code using SMO
Microsoft has also released a tool called 'mssql-scripter'. It can be found here: mssql-scripter
I wrote SMOscript, a command line tool to script all objects into a single file, or one file for all objects.
The Generate Scripts function of MSSQL typically does not consider references and dependencies to determine the sequence of objects (at least that was the case with 2000 and 2005)
I used http://www.codeplex.com/ScriptDB with great success.
You could invoke a standard select clause (using ADO.NET for example) over the sysobjects view.