Tuesday, March 27, 2012

Cannot enable xp_cmdshell using DMO and VBScript

Hi,

I am trying to enable xp_cmdshell using VBScript and DMO in SQL Server 2005 Express.
But I get errror "Item cannot be found in collection corrosponding to the requested name or ordinal"

Following is the script:

Dim excmd: Set excmd = CreateObject("ADODB.Command")
Set excmd.ActiveConnection = connx ' This is connected to master database using sa account

excmd.CommandType = 4
excmd.CommandText = "sys.sp_configure"
excmd.Parameters.Refresh
excmd.Parameters(1).Value = "show advanced options"
excmd.Parameters(2).Value = 1
excmd.Parameters(3).Value = Null
excmd.Execute () ' This line fails
If (Err.Number <> 0) Then
LogText "Unable to execute stored procedure. " & Err.Number & " " & Err.Description
Exit Sub
End If

excmd.CommandText = "RECONFIGURE WITH OVERRIDE"
excmd.Parameters.Refresh
excmd.Execute ()
If (Err.Number <> 0) Then
LogText "Unable to Refresh. " & Err.Number & " " & Err.Description
Exit Sub
End If

excmd.CommandText = "sys.sp_configure"
excmd.Parameters.Refresh
excmd.Parameters(1).Value = "xp_cmdshell"
excmd.Parameters(2).Value = 1
excmd.Parameters(3).Value = Null
excmd.Execute ()

If (Err.Number <> 0) Then
LogText "Unable to execute sp xp_cmdshell. " & Err.Number & " " & Err.Description
Exit Sub
End If

excmd.CommandText = "RECONFIGURE"
excmd.Parameters.Refresh
excmd.Execute ()
If (Err.Number <> 0) Then
LogText "Unable to Refresh after running sp. " & Err.Number & " " & Err.Description
Exit Sub
End If

Could any body tell me what I am missing here.

Thanks in advance
Amit

Please do not multipost, answered in http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1989334&SiteID=1

Jens K. Suessmeyer

http://www.sqlserver2005.de

No comments:

Post a Comment