A
alex2345
Простая замена для xp_cmdshell
С возможностью раздачи прав на доступ.
С возможностью раздачи прав на доступ.
Код:
declare @iShl int, @iStm int, @iStdOut int, @iLine int, @hr int, @EndOfStream int,
@strText nvarchar(4000), @cmd nvarchar(4000)
set @cmd = 'Exec("cmd /c ping -n 3 -w 1000 www.ru")'
EXEC @hr = sp_OACreate 'Wscript.Shell', @iShl OUT
EXEC @hr = sp_OAMethod @iShl, @cmd, @iStm out
EXEC @hr = sp_OAGetProperty @iStm, 'StdOut', @iStdOut out
EXEC @hr = sp_OAGetProperty @iStdOut, 'AtEndOfStream', @EndOfStream out
WHILE @EndOfStream = 0 BEGIN
EXEC @hr = sp_OAGetProperty @iStdOut, 'ReadLine', @strText out
print @strText
EXEC @hr = sp_OAGetProperty @iStdOut, 'AtEndOfStream', @EndOfStream out
END
EXEC @hr = sp_OADestroy @iShl