January 6, 2011 at 4:07 pm
Is there a way i can find the actual path of sqlservr.exe? Any system table?.I could use command shell but i do not how to findout if it is installed on other drive than C.
January 6, 2011 at 4:45 pm
the server executable itself is always installed on the same disk the %SYSTEMDRIVE% directory exists; databases, traces ,previous backups you can discover form some of the system views, but all those items can have been moved to disks other than the OS drive;
what is it you are trying to find?
here's a decent list of all the windows command line variables:
Lowell
January 7, 2011 at 3:53 am
@sqldba_icon,
You can also query the SQLBinRoot key in the registry. It is located in the following key for SQL Server 2008 default instance. You may navigate to the Setup key for SQL Server 2005 in registry.
Pradeep Adiga
Blog: sqldbadiaries.com
Twitter: @pradeepadiga
January 7, 2011 at 1:10 pm
I understand where the binaries are located. Basically i have 50 servers and i do not want to physically log into services console of each of these servers to find where the sqlserver.exe is located. I just wanted to pass a dos command through xp_cmdshell usign 2008 client which will should tell me which drive is the executable placed. How do i do that now? Thanks
January 7, 2011 at 1:24 pm
Pls Check this ,
Declare @path nvarchar(100)
Declare @instance_name nvarchar(100)
Declare @instance_name1 nvarchar(100)
Declare @system_instance_name nvarchar(100)
Declare @key nvarchar(1000)
SET @instance_name = coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');
If @instance_name!='MSSQLSERVER'
Set @instance_name=@instance_name
Set @instance_name1= coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');
If @instance_name1!='MSSQLSERVER'
Set @instance_name1='MSSQL$'+@instance_name1
EXEC master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\SQL', @instance_name, @system_instance_name output;
Set @key=N'SYSTEM\CurrentControlSet\Services\' +@instance_name1;
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='ImagePath',@value=@path OUTPUT
Select @path as Binaries_Path
Thank You,
Best Regards,
SQLBuddy
January 7, 2011 at 1:45 pm
sqlbuddy123 (1/7/2011)
Pls Check this ,
Declare @path nvarchar(100)
Declare @instance_name nvarchar(100)
Declare @instance_name1 nvarchar(100)
Declare @system_instance_name nvarchar(100)
Declare @key nvarchar(1000)
SET @instance_name = coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');
If @instance_name!='MSSQLSERVER'
Set @instance_name=@instance_name
Set @instance_name1= coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');
If @instance_name1!='MSSQLSERVER'
Set @instance_name1='MSSQL$'+@instance_name1
EXEC master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\SQL', @instance_name, @system_instance_name output;
Set @key=N'SYSTEM\CurrentControlSet\Services\' +@instance_name1;
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='ImagePath',@value=@path OUTPUT
Select @path as Binaries_Path
Thank You,
Best Regards,
SQLBuddy
This is exactttttttttly what i was looking for. Awesome. Thank you so muchhhhhhhh
February 8, 2016 at 2:45 pm
sqlbuddy123 (1/7/2011)
Pls Check this ,
Declare @path nvarchar(100)
Declare @instance_name nvarchar(100)
Declare @instance_name1 nvarchar(100)
Declare @system_instance_name nvarchar(100)
Declare @key nvarchar(1000)
SET @instance_name = coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');
If @instance_name!='MSSQLSERVER'
Set @instance_name=@instance_name
Set @instance_name1= coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');
If @instance_name1!='MSSQLSERVER'
Set @instance_name1='MSSQL$'+@instance_name1
EXEC master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\SQL', @instance_name, @system_instance_name output;
Set @key=N'SYSTEM\CurrentControlSet\Services\' +@instance_name1;
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='ImagePath',@value=@path OUTPUT
Select @path as Binaries_Path
Thank You,
Best Regards,
SQLBuddy
Great script. Resurrecting this thread from 2011 to say that if you wind up getting a NULL for the @path variable, extend it out to a nvarchar(200). We had a long named instance of SQL, and it went beyond the 100 character limit for that key value, and as a result, it returned null rather than a truncated string.
Thought that might help someone down the road!
Cheers,
Steve 😀
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply