try this code
i get it from here
DECLARE @retvalue int, @data_dir varchar(500)
EXECUTE @retvalue = master.dbo.xp_instance_regread 'HKEY_LOCAL_MACHINE',
'SOFTWARE\Microsoft\MSSQLServer\Setup',
'SQLDataRoot', @param = @data_dir OUTPUT
PRINT 'SQL Server Data Path: '+ @data_dir
Comments