需要帮助从下面的代码中禁用xp_cmdshell。我们可以采取什么程序来禁用xp_cmdshell。
-- Add the job
EXECUTE @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID OUTPUT , @job_name = N'ExportXYZPRTE', @owner_login_name = N'SORTADM', @description = N'Export TAPPRTE Table', @category_name = N'[Uncategorized (Local)]', @enabled = 1, @notify_level_email = 0, @notify_level_page = 0, @notify_level_netsend = 0, @notify_level_eventlog = 2, @delete_level= 0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the job steps
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID, @step_id = 1, @step_name = N'export', @command = N'DECLARE @CMD varchar(100)
--Export from XYZPRTE Table
SET @CMD = ''dtsrun /FC:\program files (x86)\XYZAPPS\OAS\programs\XYZPRTEExport.dts''
EXEC master..xp_cmdshell @CMD', @database_name = N'master', @server = N'', @database_user_name = N'', @subsystem = N'TSQL', @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0, @retry_interval = 1, @output_file_name = N'', @on_success_step_id = 0, @on_success_action = 1, @on_fail_step_id = 0, @on_fail_action = 2
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXECUTE @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 请帮我更换这个xp_cmdshell。
发布于 2022-02-15 15:47:33
下面是我写了一段时间的过程--它只是删除服务器上的一些*.csv文件。只需从这里替换delete语句,然后用您正在做的替换。
CREATE PROCEDURE DeleteCSV
-- Add the parameters for the stored procedure here
@Result as VARCHAR(10) OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRY
-- Insert statements for procedure here
EXEC sp_configure 'show advanced options', '1'
RECONFIGURE
-- this enables xp_cmdshell
EXEC sp_configure 'xp_cmdshell', '1'
RECONFIGURE
DECLARE @cmd NVARCHAR(MAX) =
'xp_cmdshell ''del "C:\temp\*.csv"'''
EXEC (@cmd)
-- this disables xp_cmdshell
EXEC sp_configure 'xp_cmdshell', '0'
RECONFIGURE
-- this turns off advanced options and is needed to configure xp_cmdshell
EXEC sp_configure 'show advanced options', '0'
RECONFIGURE
SET @Result = 'Success'
print @Result
END TRY
BEGIN CATCH
SET @Result = 'Failure'
END CATCH
ENDhttps://stackoverflow.com/questions/71120963
复制相似问题