0

When I execute the following statement in SQL Server 2008 :

use master
go
exec sp_configure 'show advanced options', 1;
go
reconfigure
go
exec sp_configure 'xp_cmdshell',1;
go
reconfigure
go
EXEC XP_CMDSHELL 'whoami'

It gives the following error:

Msg 15121, Level 16, State 21, Procedure xp_cmdshell, Line 1 An error occurred during the execution of xp_cmdshell. A call to 'CreateProcess' failed with error code: '2'.

Please help me with this problem.

Thank you so much.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Yen
  • 1
  • 1
  • Error code 2 means `File not found`. Does it work if you use `exec xp_cmdshell 'C:\Windows\System32\whoami.exe'` or `exec xp_cmdshell 'C:\Windows\SysWOW64\whoami.exe'` instead? – AlwaysLearning Dec 19 '20 at 05:22
  • Thank you. But it didn't work. – Yen Dec 21 '20 at 07:04
  • Are you able to logon to the Windows Server that's hosting this SQL Server instance? Can you confirm that it actually has a `whoami.exe` on it anywhere? (i.e.: a sysadmin may have chosen to delete it.) – AlwaysLearning Dec 21 '20 at 09:23
  • I still can excute "whoami" on Command Line. It's OK. – Yen Dec 21 '20 at 09:55

1 Answers1

0

Error code 5 means - access denied.

Please check if account which used for MSSQL service has right on command that you trying to run.

Details: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/bbdffb3c-6604-4011-ac5f-5ea8ecb1a32c/xpcmdshell-a-call-to-createprocess-failed-with-error-code-5-under-sql2005-rtm?forum=sqlsecurity

Nader Gharibian Fard
  • 6,417
  • 4
  • 12
  • 22