Read Registry

  • I need a script to find below information from remote servers:

    INSTANCE PORT Number (From Registry)

    collation from SERVERPROPERTY

    Could any one please help? Many thanks in advance

  • I think you should check out xp_cmdshell. You can then create your own exe to read the registery and call it from the shell.

    How To Post[/url]

  • well, if you run the script below, it will read the registry and tell you teh listening port...

    i duoubt this will work over a linked server, which is what i assume you mean by a remote server?

    CREATE TABLE #GetPort

    (

    token varchar(100),

    value varchar(20))

    go

    DECLARE @inst varchar(200)

    DECLARE @inst1 varchar(100)

    --Determine registry path and key

    IF(charindex('\',@@servername) > 0)

    BEGIN

    SELECT @inst = substring(@@servername,charindex('\',@@servername) ,50)

    SELECT @inst = 'SOFTWARE\Microsoft\Microsoft SQL Server'+@inst+'\MSSQLServer\SuperSocketNetLib\Tcp'

    --SELECT @inst1 = 'TcpDynamicPorts'

    SELECT @inst1 = 'TcpPort'

    END

    ELSE

    BEGIN

    if SUBSTRING(@@VERSION,23,1) = '7'

    begin

    SELECT @inst = 'SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib\VIA'

    SELECT @inst1 = 'DefaultServerPort'

    end

    else

    begin

    SELECT @inst = 'SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib\Tcp'

    SELECT @inst1 = 'DefaultPort'

    end

    END

    print @inst + '\\\\////'+ @inst1

    INSERT #GetPort

    EXEC master..xp_regread 'HKEY_LOCAL_MACHINE', @inst, @inst1

    SELECT substring(@@servername,1,25) as ServerName, value as port FROM #GetPort

    DROP TABLE #GetPort

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you both for the idea and scrpit. I am working on this..

    I understand that the script given will work if I am connected to server only. However the issue is I can not connect to the servers. So I need to run this (similer) code against all servers (name will be found in a table) using some batch

    If you have furher idea.. plz share

    Thanks again

  • i tried running the command over a linked server; basically i tried changing the last command to a 4 part command:

    EXEC linkedservername.master..xp_regread 'HKEY_LOCAL_MACHINE', @inst, @inst1

    got this error:

    SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp\\\\////TcpPort

    Msg 7411, Level 16, State 1, Line 43

    Server 'db1' is not configured for RPC.

    maybe if RPC was enabled for the server, but i dunno...it's getting out of my area of knwoledge.

    i think you'll have to do this in a programming language, or use RegEdit to connect to the remote machines using your domain credentials manually.

    you could also try SQLRecon.exe, which scans a network for servers and reports back a lot of information, but it is not possible via a linked server.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks a lot... I will try to explore from my end also and will post here if I get a better way..

    Thanks again 🙂

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply