When you run xp_cmdshell
, SQL server will start a new process. The user which this process runs as can vary depending on the user configured to run SQL server and whether the SQL agent is enabled.
To find which user the command runs as (I'm assuming at least Windows 7 on the server), execute:
EXEC xp_cmdshell 'whoami & cd & path'
The first line will be the user who is running xp_cmdshell
, the second shows what the proces' working directory is and the rest will list the folders in the path.
To check effective permissions, use Explorer to navigate to:
- "d:\" Properies
- Security
- Advanced
- Effective permissions
- 'Select' and enter the name returned from
whoami
E.g. on my system, whoami returned nt authority\network service
which is NETWORK SERVICE
for the effective security dialog.
The path output will include a 'SQL server\xxx\binn' folder, check that the first of these matches the version of SQL your connected server is running - otherwise you may have to specify the path explicitly.