Kuzhikkattil

Just another WordPress.com weblog

‘xp_cmdshell’

EXEC sp_configure ’show advanced option’, ‘1′
 EXEC sp_configure ‘xp_cmdshell’, ‘1′ RECONFIGURE WITH OVERRIDE;

Please run the following script before
Private Function ExecBatFile(ByVal BatchFilePath As String, ByVal ScriptFile As String, ByVal userid As String, ByVal password As String, ByVal strSqlServerInstanceName As String, ByVal strTempScriptFile As String) As Boolean
        Dim CmdEx As New SqlCommand
        Dim testconn As New SqlConnection(BuildConnectionString(userid, password, strSqlServerInstanceName, “master”))
        Dim strCommand As String = String.Concat(New String() {” EXEC xp_cmdshell ‘”, ScriptFile, “\poc-bat.bat “”", userid, “”" “”", password, “”" “”", strSqlServerInstanceName, “”" “”", strTempScriptFile, “”"‘”})
        Try
            testconn.Open()
            CmdEx.Connection = testconn
            CmdEx.CommandType = CommandType.Text
            CmdEx.CommandText = strCommand
            CmdEx.ExecuteNonQuery()
        Catch ex As Exception
            Return False
        End Try

        Return True
    End Function

March 28, 2008 Posted by kuzhikkattil | Uncategorized | | No Comments Yet