Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MScopyregvalue

  No additional text.


Syntax

-- Name: sp_MScopyregvalue

-- Descriptions:

-- Parameters: as defined in create statement

-- Returns: 0 - success
--          1 - Otherwise

-- Security:
-- Requires Certificate signature for catalog access

create procedure sys.sp_MScopyregvalue(
    @oldregkey            nvarchar(1000),
    @newregkey            nvarchar(1000),
    @param_type            nvarchar(20),
    @param_name            sysname)
as
    set nocount on
    declare @retcode     int
    create table #binaryvalues ( value sysname collate database_default, data varbinary(256))
    if (@param_type = 'REG_SZ')
    begin
        declare @value_str nvarchar(1000)
        set @value_str = NULL
        -- Read value from old reg location and write to new one
        EXECUTE @retcode = master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
                               @oldregkey,
                               @param_name,
                               @param = @value_str OUTPUT,
                               @no_output = 'no_output'
        if @retcode <> 0 or @@ERROR <> 0
        begin
            set @retcode = 0
            goto FAILURE
        end
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @newregkey,
                           @param_name,
                           'REG_SZ',
                           @value_str
        if @retcode <> 0 OR @@ERROR <> 0
        begin
            set @retcode = 1
            goto FAILURE
        end
    end

    if (@param_type = 'REG_DWORD')
    begin
        declare @value_int int
        set @value_int = NULL
        -- Read value from old reg location and write to new one
        EXECUTE @retcode = master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
                               @oldregkey,
                               @param_name,
                               @param = @value_int OUTPUT,
                               @no_output = 'no_output'
        if @retcode <> 0 or @@ERROR <> 0
        begin
            set @retcode = 0
            goto FAILURE
        end
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @newregkey,
                           @param_name,
                           'REG_DWORD',
                           @value_int
        if @retcode <> 0 OR @@ERROR <> 0
        begin
            set @retcode = 1
            goto FAILURE
        end
    end

    if (@param_type = 'REG_BINARY')
    begin
        declare @value_binary varbinary(256)
        set @value_binary = NULL
        -- Read value from old reg location and write to new one
/*
-- binary output buffer was corrupted for a couple of builds;looks to be working now
-- if reverting to this read, must pre-check exists on regkey to avoid regopenkey failure
-- on non-existent key when no OUTPUT parm specified
        insert into #binaryvalues EXECUTE master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
                               @oldregkey,
                               @param_name
        if @@ERROR <> 0
            begin
                set @retcode = 0
                goto FAILURE
            end
        select @value_binary = data from #binaryvalues
        if @value_binary is NOT NULL
            EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @newregkey,
                               @param_name,
                            'REG_BINARY',
                               @value_binary

*/
        EXECUTE @retcode = master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
                               @oldregkey,
                               @param_name,
                               @param = @value_binary OUTPUT,
                               @no_output = 'no_output'
        if @retcode <> 0 or @@ERROR <> 0
        begin
            set @retcode = 0
            goto FAILURE
        end
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @newregkey,
                           @param_name,
                           'REG_BINARY',
                           @value_binary
        if @retcode <> 0 OR @@ERROR <> 0
        begin
            set @retcode = 1
            goto FAILURE
        end
    end

    set @retcode = 0
FAILURE:
    drop table #binaryvalues
    return @retcode

 
Last revision 2008RTM
See also

  sp_MScopy_subscription_regkeys (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash