Question

In a stored procedure, i execute master.dbo.sp_fileexist and master.dbo.xp_cmdshell and it's work really good when i'm using SA user, but when i use my db_owner user, i have this error.

[FR]
Msg 15247, Niveau 16, État 1, Procédure sp_configure, Ligne 94
L'utilisateur n'est pas autorisé à effectuer cette action.
[/FR]
[EN]
Msg 15247, Level 16, State 1, Procedure sp_configure, Line 94 
The user is not authorized to perform this action.
[/EN]

But i need too use sp_configure to allow xp_cmdshell.

EXEC sp_configure 'show advanced option', '1';
Reconfigure
Exec sp_configure 'xp_cmdshell', 1
Reconfigure

If someone can help me, please.

Était-ce utile?

La solution

For users that are not members of the sysadmin role on the SQL Server instance you need to do the following actions to grant access to the xp_cmdshell extended stored procedure.
*A system administrator can enable the use of 'xp_cmdshell' by using sp_configure.*

  • Enable the xp_cmdshell procedure:

    EXEC sp_configure 'show advanced options', 1
    RECONFIGURE
    GO
    
    EXEC sp_configure 'xp_cmdshell', 1
    RECONFIGURE
    GO
    
  • Grant EXEC permission on the xp_cmdshell stored procedure:

    GRANT EXECUTE ON xp_cmdshell TO [Domain\TestUser]

To do it yourself you need serveradmin or sysadmin privileges privs for that

Autres conseils

I suggest that you create a stored procedure with sp_configure to allow xp_cmdshell in it and use even parameters to pass to the sp_configure procedure, create a procedure with execute as owner, than grant execute for this procedure to the users you like :)

I think that by this way you are doing things correctly and safely

I hope this will help you.

Good Luck

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top