Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Простая замена для Xp_cmdshell
Форум программистов > Базы данных и администрирование > SQL
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
European
Хвастаешься?
sax_ol
чето эта, сильно не разбираслся вкинул на выполнение и вот
Цитата
Msg 15281, Level 16, State 1, Procedure sp_OACreate, Line 1
SQL Server blocked access to procedure 'sys.sp_OACreate' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online.
Msg 15281, Level 16, State 1, Procedure sp_OAMethod, Line 1
SQL Server blocked access to procedure 'sys.sp_OAMethod' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online.
Msg 15281, Level 16, State 1, Procedure sp_OAGetProperty, Line 1
SQL Server blocked access to procedure 'sys.sp_OAGetProperty' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online.
Msg 15281, Level 16, State 1, Procedure sp_OAGetProperty, Line 1
SQL Server blocked access to procedure 'sys.sp_OAGetProperty' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online.
Msg 15281, Level 16, State 1, Procedure sp_OADestroy, Line 1
SQL Server blocked access to procedure 'sys.sp_OADestroy' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online.


PS: я к тому что надо пояснять заранее
alex2345
Sorry,
тестировал на SQL 2000. Там всё работает без дополнительных настроек.

В SQL 2005 нужно выполнить:

Код
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
alex2345
analogue xp_cmdshell
замена для xp_cmdshell
---------------------------------------------------------------------
Windows 2000: need Windows Script 5.6 for Windows XP and Windows 2000
Windows 2003: included
---------------------------------------------------------------------
MSSQL2000 :
nothing, Ole Automation Procedures enabled

MSSQL2005 :
Код
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO

MSSQL2008 :
[url=http://msdn2.microsoft.com/en-us/library/ms191188(SQL.100).aspx]http://msdn2.microsoft.com/en-us/library/m...8(SQL.100).aspx[/url]
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
---------------------------------------------------------------------
declare @iShl int, @iStm int, @iStdOut int, @hr int, @EndOfStream int,
@strText nvarchar(4000), @cmd nvarchar(4000)
set @cmd = 'Exec("cmd /c ping -n 3 -w 1000 127.0.0.1")'

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

---------------------------------------------------------------------
Keywords: xp_cmdshell, faq, howto, problem, error, alternative, command line, cmd
проблема, как обойти, ошибка
---------------------------------------------------------------------

Модератор:Не забывайте про оформление поста!
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Русская версия IP.Board © 2001-2008 IPS, Inc.