0

I don't know if it should be like this. When I'm trying to do anything with xp_cmdshell procedure it almost every time gives me Access Denied.

For example I can't create new .txt file, can't create new user, nothing. I'm logged in with windows administrator user.

Is there any way to run this procedure with administrator privileges?

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164

2 Answers2

0

xp_cmdshell executed by a windows login is executing under an impersonation context. as such any access of a remote resource (eg. access a file on a share, an operation on AD like adding an user) will fall under the constrained delegation restrictions, likely resulting in a access denied because constrained delegation is probably not to be configured on all those resources.

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
0

XP_CmdShell will execute under the context of the Service Account running the SQL Server Service. The service account needs the permissions to the external resources.

Could I point out however, that enabling xp_cmdshell is not a good idea. It opens lots of security holes. For example, if your app has an unknown volnerability to SQL injection, a hacker could do all sorts on your network that you rather avoid.

If you must use external resources then better approaches would include a CLR procedure or calling a Job that executes a CMDEXEC step.

Pete Carter
  • 2,691
  • 3
  • 23
  • 34