Search code examples
sql-server-2008exexp-cmdshell

Unable to execute a '.exe' file from SQL Server 2008


I am trying to execute an .exe file from a SQL query. I am not sure whether the output I receive is valid.

This is my query:

exec master..xp_cmdshell 'dir C:\Users\My_PC\Desktop\Items\dist\runfile.exe'

And I get the following result:

Volume in drive C has no label.
Volume Serial Number is 1256-8E4B
NULL
 Directory of C:\Users\My_PC\Desktop\Items\dist
NULL
13/06/2016  17:08         6,794,192 runfile.exe
               1 File(s)      6,794,192 bytes
               0 Dir(s)  10,165,284,864 bytes free
NULL

Ideally, executing the runfile.exe should invoke the command prompt. But it isn't. Any help or suggestion would be appreciated.


Solution

  • That was a good test. You have proved your path is working, you can run a command and receive output.

    Now remove dir to run the command.

    exec master..xp_cmdshell 'C:\Users\My_PC\Desktop\Items\dist\runfile.exe'