xp_cmdshell : 'Access Denied' running TaskKill

  • Hi - I'm attempting to kill a process ( exe ) using TaskKill via xp_cmdshell and am getting the message : 'ERROR: The process "blah.exe" with PID99 could not be terminated. Reason: Access is denied'.

    I am able to kill the process with KillTask via the DOS prompt. I have checked what user xp_cmdshell is running as and that user is the admin group on that server, as is my user, so in theory we should have the same rights?

    The syntax I'm using is :

    EXEC master.dbo.xp_cmdshell 'taskkill /IM blah.exe'

    Has anyone experienced this problem?

    thanks - S

  • Could it not be to do with the permissions of the user who runs the TaskKill when you execute xp_cmdshell? I think by default SQL server services are started using the Local System user account which in your system might not have the necessary privileges to kill a task. Or it could be that the services on your system are started by a local/domain user with minimal privileges.

  • ...EXEC master.dbo.xp_cmdshell 'SET USERNAME'...

    ...that user is in the Admin group...

  • To confirm, is the SQL Server startup account is part of local administrators group on the server?

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

  • Hi - SQL Server (MSSQLSERVER) in Services logs on as <<domain>>\<<server>>adm.

    This is the same user that xp_cmdshell is running as.

    That user is in the Admin group for the server.

    thansk - S

  • I've spent a bit more time on this and I've discovered that if you log onto the box as the SQL Server user, you can run taskkill OK, no problems.

    I then tried running called via cmdshell. i.e. :

    exec xp_cmdshell 'c:\blah.exe'

    I then ran another SSMS session and tried :

    exec xp_cmdshell 'taskkill /F /IM blah.exe'

    ...and it worked!

    Behaviour seems to suggest that you can only use taskkill via xp_cmdshell to kill processes started under the same user.... This sounds absolutely useless to me!?!

    Can anyone shed any light?!?

    thanks - S

  • ...and a bit more info...created a SQL Server Agent job that runs :

    xp_cmdshell 'c:\blah.exe'

    This runs under the Agent ( agt ) user id that has the same priviledges as the SQL Server ( adm ) user.

    Running taskkill via xp_cmdshell under the SQL Server ( adm ) account terminates the process.

    However, trying the same again, but running the process via a CmdExec job step, results in another 'Access Denied' error...

    Why the difference in using CmdExec and xp_cmdshell?

    thansk - S

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply