0

I been trying to research this for hours and can't seem to find anything. Basically what I am trying to do is run a xp_cmdshell command as a currently signed in sysadmin user

To give some background, I have two accounts here

  1. Domain\App_service
  2. Domain\sql_service

Now SQL_Service and app_service are both in the sysadmin role. SQL_Service is what SQL Server is running as.

The problem I'm encountering is that when I run xp_cmdshell, it executes as the sql_service user. What I need to do is run this as the app_service as the command I am executing has the folder permissions locked down to app_service user

Here is an example of the code that I have tried to make it run as app_service

Execute as login='DOMAIN\app_service'
Exec xp_cmdshell 'whoami'

It keeps returning the sql_service user. From what I am researching, I believe that is intended by design. However, I am trying to run the cmd_shell as the domain\app_service user. This user is a local system admin and in the sysadmin server roles. And I'm running as this user in SQL Server Management Studio and the query is running as this user.

I keep seeing information around in regards to running non sysadmin users with xp_cmdshell. However, I'm not doing that. I'm simply just trying to run under a particular sysadmin user instead of xp_cmdshell running as the sql service username.

migrated from stackoverflow.com Mar 15 at 21:30

This question came from our site for professional and enthusiast programmers.

  • Xp_cmdshell does not allow OS user impersonation and it’s probably not a good idea to use it anyway. Better call a external service via MQ, HTTP or by having the external service poll a job table. – eckes Mar 15 at 21:55
  • Anyone wrong with using the cmdexec step? You could then use a proxy. – Sean Gallardy Mar 16 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy