Get all system databases of a server

The easiest way for querying all system databases of a server is to assume that databases create by a user come with a database_id >= 5 in sys.databases. But the problem is that distribution databsaes will not be kept into this consideration. Therefore SMO does the following behind the scenes (bioled down to the relevants facts) while querying the objectmodel for the property Server.Database[n].IsSystemObject

CAST(case when in (‘master’,’model’,’msdb’,’tempdb’) then 1 else dtb.is_distributor end AS bit) AS [IsSystemObject]
master.sys.databases AS dtb