EXEC master..xp_cmdshell

Posted on 2007-07-25
Medium Priority
Last Modified: 2008-01-09
I have a .exe on a web server eg.  (\\\webserver\folder1\my.exe)

I have a mapped drive to that web server.

What I am trying to do is run a SQL Server Agent job to run my .exe on my web server.

I used the following :

Operating System Command (CmdExec)

EXEC master..xp_cmdshell '\\\webserver\folder1\my.exe'

This doesn't work.  
I have full read/write access to the server

What am i doing wrong?
Question by:joan2006
  • 4
  • 3

Author Comment

ID: 19566284
Here is the error i get

Executed as user: na\svc-sqlinst25-clst11. The process could not be created for step 1 of job 0xCA1E88B11062954B8C0E801C72F923E1 (reason: The system cannot find the file specified).  The step failed.
LVL 21

Accepted Solution

mastoo earned 2000 total points
ID: 19567744
Your access doesn't matter.  The command will run under the context of whatever account sql server is running.  Generally that account won't have network permissions.
LVL 50

Expert Comment

ID: 19567849

EXEC master..xp_cmdshell 'X:\my.exe'

where X: is the drive you've mapped to '\\\webserver\folder1'

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.


Author Comment

ID: 19567875
So, are you saying that i can only run a .exe from my machine and not on the web server???

LVL 21

Expert Comment

ID: 19567966
Probably just from whatever box is hosting sql server.  A quick test would be try this:

exec master..xp_cmdshell 'dir'

and it probably works, showing you the results.  Then try this:

exec master..xp_cmdshell 'dir \\SomePuter\SomeShare'

and if they have default security in place you'll get "Access is denied", meaning you can't get to the network under the sql server account.

Author Comment

ID: 19568032


I tried:

EXEC master..xp_cmdshell 'R:\KJG\my.exe'

no luck ...i still get this error when i look at the history file

Executed as user: na\sv......... The process could not be created for step 1 of job 0xCF127805D24B9D4B8328B4AC8C9D1A5E (reason: The system cannot find the file specified).  The step failed.

Author Comment

ID: 19568077

i tried your suggestion and got this error:

Executed as user: na\svc-........... The process could not be created for step 1 of job 0xCF127805D24B9D4B8328B4AC8C9D1A5E (reason: The system cannot find the file specified).  The step failed.

What should i have selected in the Category dropdown in the General tab for creating a job?  currently i have uncatergorized(Local) selected.
Is this correct?
LVL 21

Assisted Solution

mastoo earned 2000 total points
ID: 19569251
Sorry, I meant try my example from query analyzer first as that will tell you if you're going to be able to get to the network share.  If that pans out, then the next thing would be, why can't you run your sql agent job.  But ok, let's also see if you can create and run a simple sql agent job that runs as you and just does a select * in your database?

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question