Error al ejecutar xp_cmdshell en sql server 2019

Marroquin 1 Reputation point
2022-06-07T02:01:40.567+00:00

Realice las siguiente configuración:

EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO

-- Habilito la ejecucion del xp_cmdshell

EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO

Cree un usuario nuevo en SQL

----le doy acceso a xp_cmdshell a usuario que se creo anteriormente
GRANT EXECUTE ON [sys].[xp_cmdshell]
TO [UsuarioNuevoSQL]
GO

Asigne un usuario de windows
EXEC sp_xp_cmdshell_proxy_account
N'Dominio\Administrator',
N'Password'

en Directiva de seguridad local, agregue al usuario "administrator" en Asignación de derechos de usuario en iniciar sesion como un trabajo por lotes

y al ejecutar: xp_cmdshell 'dir "C:\TQsoft\CFDI" /s/b>C:\TQsoft\CFDI.txt'; o cualquier otro comando me marca el siguiente error:

Msg 15121, Level 16, State 10, Procedure xp_cmdshell, Line 1 [Batch Start Line 0]
An error occurred during the execution of xp_cmdshell. A call to 'CreateProcessAsUser' failed with error code: '2'.

SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. CathyJi-MSFT 22,401 Reputation points Microsoft External Staff
    2022-06-07T09:17:25.46+00:00

    Hi @Marroquin ,

    Agree with Olaf. In addition , error code 2 means File not found.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  2. Erland Sommarskog 128K Reputation points MVP Volunteer Moderator
    2022-06-07T21:49:58.517+00:00

    In addition to Cathy's answer, this a file that is needed to create the process. That is not the files on the command line, but rather a file associated with the proxy login. Make sure that the proxy login has access to the SQL Server machine.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.