SQL Server Management Objects SMO is your answer. You can use it to accomplish this task. Here is an example to generate Create Table Scripts.
public string GetTableDescription(string pDatabaseName, string pSchemaName, string pTableName, string connectionString)
{
connectionString = ConnectionHelper.RemoveProviderFromConnectionString(connectionString);
Server server = new Server(new ServerConnection(new SqlConnection(connectionString)));
Database db = server.Databases[pDatabaseName];
Table t = db.Tables[pTableName, pSchemaName];
ScriptingOptions baseOptions = new ScriptingOptions();
baseOptions.NoCollation = true;
baseOptions.SchemaQualify = true;
baseOptions.DriDefaults = true;
baseOptions.IncludeHeaders = false;
baseOptions.DriPrimaryKey = true;
baseOptions.ExtendedProperties = true;
//baseOptions.DriAll = true;
//baseOptions.Indexes = true;
//baseOptions.DriAllKeys = true;
//baseOptions.SchemaQualifyForeignKeysReferences = true;
baseOptions.EnforceScriptingOptions = true;
StringCollection result = t.Script(baseOptions);
return StringCreate(result);
}