无法通过MSSQL中的Openquery启用xp_cmdshell

问题描述

我具有实例1->实例2的DB Links访问权限。 我可以通过直接执行SQL查询在实例1中启用/禁用xp_cmdshell。但是当我尝试使用Openquery()时,我无法启用它。我在两个实例中都具有sysadmin特权。

以下查询没有结果(由于“ SELECT 1”,该错误被抑制):

$Query = "select * from openquery(""INSTANCE2"",'SELECT 1; EXECUTE(''master..sp_configure ''''show advanced option'''',1; RECONfigURE; master..sp_configure ''''xp_cmdshell'''',1; RECONfigURE;'')               ')"        
$cmd = New-Object System.Data.sqlClient.sqlCommand($Query,$conn)
$results = $cmd.ExecuteReader() 
$results.Close()

当我尝试以下查询时:

$Query = "select * from openquery(""INSTANCE2"",'EXEC master.dbo.sp_configure ''show advanced option'',1; RECONfigURE WITH OVERRIDE; EXEC master.dbo.sp_configure ''xp_cmdshell'',0; RECONfigURE;                ')"        

我遇到错误

Exception calling "ExecuteReader" with "0" argument(s): "The Metadata Could not be determined because the statement 'select name,convert(int,minimum) as minimum,maximum) as maximum,convert' in procedure 'sp_configure' is not compatible with the statement 'select duplicate_options = name
                from sys.configurations
                where lower(name collate latin1_Genera' in procedure 'sp_configure'."
At ...
+     $results = $cmd.ExecuteReader()
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [],MethodInvocationException
    + FullyQualifiedErrorId : sqlException

我不能使用openquery()启用xp_cmdshell吗?我怎么能达到同样的目的?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...