Function to read Registry

  • Hi Gurus,

    Is there any func's or SP's to read regisrty.

     




    My Blog: http://dineshasanka.spaces.live.com/

  • xp_regread

    xp_regenumkeys

    xp_regwrite

    xp_regdeletevalue

    xp_regdeletekey

    I would search for them here or on the net. None of them is documented in BOL for a very good reason.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Frank Kallis has given/said the easiest way available which is not known to most since these are undocumented. But u can use the xp_cmdshell and your dos command to do the same as well.

    But again...as in other cases u need to have Sysadmin permissions to run these xtended Procs.

    Cheers!


    Arvind

  • How would I do this with DOS commands?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Thankx Frank,

    I wonder y they have not doucmented.

    I fonund folowing code from the internet

    DECLARE @version    VARCHAR(100)

    EXECUTE master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',

      'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion',

      'CurrentVersion',

      @version OUTPUT,

      'no_output'




    My Blog: http://dineshasanka.spaces.live.com/

  • If you don't mind that it's a german site you can have a look at this here. They also have a sample script. As this is mostly code it shouldn't be hard to follow.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • See Windows NT Resouce Kit for such tools

     


    -- Amit



    "There is no 'patch' for stupidity."



    Download the Updated SQL Server 2005 Books Online.

  • Say for ex, you can use it to export the registry by

    xp_cmdshell 'regedit /e registry.txt'

    Change and import it back...Just a work around.

     

    Cheers!


    Arvind

  • you can make a VB program that read from the registery and then use this in SQL

    xp_cmdshell "c:\myVbProgram.exe"


    Alamir Mohamed
    Alamir_mohamed@yahoo.com

  • You an these also,

     

    xp_regdeletekey

    This extended stored procedure will delete an entire key from the registry. You should use it very carefully.

    Syntax:

    EXECUTE xp_regdeletekey [@rootkey=]'rootkey',                        [@key=]'key' 

    For example, to delete the key 'SOFTWARE\Test' from 'HKEY_LOCAL_MACHINE', run:

    EXEC master..xp_regdeletekey     @rootkey='HKEY_LOCAL_MACHINE',       @key='SOFTWARE\Test'

    xp_regdeletevalue

    This extended stored procedure will delete a particular value for a key in the registry. You should use it very carefully.

    Syntax:

    EXECUTE xp_regdeletevalue [@rootkey=]'rootkey',                          [@key=]'key',                          [@value_name=]'value_name'

    For example, to delete the value 'TestValue' for the key 'SOFTWARE\Test' from 'HKEY_LOCAL_MACHINE', run:

    EXEC master..xp_regdeletevalue     @rootkey='HKEY_LOCAL_MACHINE',     @key='SOFTWARE\Test',     @value_name='TestValue'

    xp_regread

    This extended stored procedure is used to read from the registry.

    Syntax:

    EXECUTE xp_regread [@rootkey=]'rootkey',                   [@key=]'key'                   [, [@value_name=]'value_name']                   [, [@value=]@value OUTPUT] 

    For example, to read into the variable @test-2 from the value 'TestValue' from the key 'SOFTWARE\Test' from the 'HKEY_LOCAL_MACHINE', run:

    DECLARE @test varchar(20)EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',  @key='SOFTWARE\Test',  @value_name='TestValue',  @value=@test OUTPUTSELECT @test

    xp_regwrite

    This extended stored procedure is used to write to the registry.

    Syntax:

    EXECUTE xp_regwrite [@rootkey=]'rootkey',                    [@key=]'key',                    [@value_name=]'value_name',                    [@type=]'type',                    [@value=]'value'

    For example, to write the variable 'Test' to the 'TestValue' value, key 'SOFTWARE\Test', 'HKEY_LOCAL_MACHINE', run:

    EXEC master..xp_regwrite     @rootkey='HKEY_LOCAL_MACHINE',     @key='SOFTWARE\Test',     @value_name='TestValue',     @type='REG_SZ',     @value='Test'

     

     

    Regards,

     

    Prashant Thakwanithakwani_prashant@yahoo.co.in

  • You missed this one xp_regenumkeys

    Or am I blind?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Any idea who may execute them?

    I can see that by default PUBLIC has execute permission on xp_regread but what about the rest? When executed from SQL Server what account actually read/write the registry? i.e. is the SQL sever domain account or proxy account or individual login that tries to execute? Because I guess that no matter who executes it from T-SQL it all depends of who actually gets access to the registry and what rights he/she has.

    Because they are undocumented I cannot get any information about who can run them.

    And something else: any problem if they are completly removed (i.e. deleted from master database)? I think I read somewhere about removing them, but I can't recall where and what.

     

    Any answer will be highly appreaciated.

     

    Gabriela

Viewing 12 posts - 1 through 11 (of 11 total)

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