-- 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