In SQL Server Management Studio, there is an option to set the default database path for a given instance:

This works. When I say
CREATE DATABASE test
it gets created in the path I specify, E:\data. Great.
But how do I get this path in T-SQL (for use in setup scripts)?
Contrary to what many pages say, there is no registry key (on my machine) for DefaultData or DefaultLog. I am running SQL Server 2005 Express on XP 64.
This value has got to be stored somewhere. Where?
Do you have access to SQL Profiler?
I don’t have SQL 2005 Express installed but when I view that properties page on my machine with Profiler running I can see where SQL Server retrieves it from on my SQL 2008 instance.
Edit: The above also works for me on SQL Server 2005 Developer edition but only after I changed the default path to something other than the default.