Finding Database Default Locations I am working on creating a script to restore database from a backup file to default location of an instance, which is set away from system databases installation folder. 

Currently, I'm using to find default DATA Location

 SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
    FROM master.sys.master_files
    WHERE database_id = 1 AND file_id = 1


and default LOG Location 

 SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'mastlog.ldf', LOWER(physical_name)) - 1)
    FROM master.sys.master_files
    WHERE database_id = 1
        AND file_id = 2
    )


Is there any other way to find database default location with the help of query?

Thank you for time.
Most SQL Servers are configured for the non-system databases to exist apart from the system databases.  That is what is normally meant by the default path.

You can lookup some code for finding this at:

http://www.codeproject.com/Articles/684020/Checking-MS-SQL-Server-database-files-default-path

Also, Alex Aza has provided a popular post over at StackOverflow. The key is to get the data from the registry keys where they are stored.  Here is a snippet from Alex's longer script:

declare @DefaultData nvarchar(512)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',
   N'Software\Microsoft\MSSQLServer\MSSQLServer', 
   N'DefaultData', @DefaultData output

declare @DefaultLog nvarchar(512)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',
   N'Software\Microsoft\MSSQLServer\MSSQLServer', 
   N'DefaultLog', @DefaultLog output