Questions tagged [xp-cmdshell]

an extended stored procedure provided by SQL Server, which launches a Windows command shell to run a specified command. Not for general questions about cmd.exe or batch scripting; not related to Windows XP.

The xp_cmdshell extended stored procedure runs the command string given and returns any output as rows of text. The documentation (for SQL Server 2012) can be found here.

For security reasons, xp_cmdshell is disabled by default in recent versions of SQL Server.

264 questions
0
votes
0 answers

Output Type From 'xp_cmdshell'

In the SQL Docs (xp_cmdshell (Transact-SQL) - Result Sets) it mentions that xp_cmdshell should output as an nvarchar(255) column Result Sets Executing the following xp_cmdshell statement returns a directory listing of the current directory. EXEC…
Kevin Pione
  • 299
  • 3
  • 12
0
votes
0 answers

How to put the powershell errors into a single column

I am running a PowerShell script(which runs a loop) using XP-cmdshell. I am trying insert the error output into a temp table. My script returns single line warning as well as multiple line errors from PowerShell. The errors are inserted into…
0
votes
0 answers

Scriptblocking A Perfectly good Powershell Script within xp_CMDShell

I have a script that works perfectly in powershell. You give it a video file and it tells you all the extended attributes. I'm trying to execute this from SQL's XPCmdShell by surrounding it with a script block like "&{my code goes here}" but that…
jimerb
  • 67
  • 9
0
votes
0 answers

Mapping Drives To Your SQL Script NET USE

I do a lot of work with the file system in my SQL scripts. After a lot of effort, the only way I'm able to get all my network shares and NAS devices to be available to my SQL scripts is to start the script off with a "Net Use" command to map a drive…
jimerb
  • 67
  • 9
0
votes
1 answer

xp_cmdshell. A call to 'CreateProcess' failed with error code: '2'

When I execute the following statement in SQL Server 2008 : use master go exec sp_configure 'show advanced options', 1; go reconfigure go exec sp_configure 'xp_cmdshell',1; go reconfigure go EXEC XP_CMDSHELL 'whoami' It gives the following…
Yen
  • 1
  • 1
0
votes
1 answer

Stored procedure with bcp hangs, but works when run as a script

I've been working on exporting a table to a file, and had problems with the bcp (bulk copy program) part of the procedure locking up. The code worked fine when I ran it as a script, but would generate locked processes when I wrapped it in a stored…
John Hunter
  • 19
  • 1
  • 4
0
votes
0 answers

SQL Server 2008 R2 to run external winform app, does not work, still showing "executing query"

On SQL Server 2008 R2 Management Studio, running a SQL command like: EXEC Master..xp_cmdshell 'C:\path_to_my_winform_app.exe" doesn't load my winforms app, says "executing query" but never runs my app. I need to use SQL to run my own app, which is…
0
votes
1 answer

xp_cmdshell in sql server - fire-and-forget or wait-for-reply?

When I use xp_cmdshell to zip files or hash files on a server in a stored procedure with a nex following T-sql statement to write a datetime into a log table, is this datetime after the zip cmd or hash cmd has finished on the server (wait for…
Gideon
  • 5
  • 1
0
votes
1 answer

SQL Server xp_cmdshell 'access is denied' on network share

I'm using xp_cmdshell to get files information from network share like this: EXEC master..xp_cmdshell 'dir \\Server\share\folder' but i get output 'access is denied' I figured out my account was NT Service\mssqlserver that can't get access to local…
0
votes
0 answers

Xp_cmdshell output 'Access denied' when execute map drive folder on SQL Server

I want to get files information on share folder using this command : EXEC master..xp_cmdshell 'dir \\Server\d$\folder1\folder2' but I get an error Access is denied When I tried using cmd it works with dir command. Is there any permission or…
0
votes
0 answers

Insert results of EXEC master..xp_cmdshell 'Query User' into a table column wise

Would it be possible to return the results of the following query into a table in SQL Server column wise. exec master..xp_cmdshell 'Query User' I have tried the following but this only returns one row with a string. declare @tbl table (output…
0
votes
0 answers

Backup database using sqlcmd command during transaction and the DB tables are not located in the backup file

I'm trying to backup a database using sqlcmd command during a transaction and any tables created during the transaction were not added to the backup file for some reason. Any idea why? BEGIN TRAN [Test] BEGIN TRY DECLARE…
0
votes
0 answers

Using net use to configure a network share for access is not persisted when SQL Server (or the server) is restarted

We are doing the following to give SQL Server access to a network drive (using a specific username and password) to allow backups to be written to subdirectory2 on the network share networklocation: EXEC sp_configure 'show advanced options',…
Ian Hannah
  • 131
  • 1
  • 1
  • 10
0
votes
1 answer

How to separate a result of one column into multiple columns in T-SQL?

I am trying to to get information about disk drives, their total space and free space (3 columns total). I found a query in the web similar to my needs but that query required some modifications. I did them but got stuck then. I can't obtain middle…
Rauf Asadov
  • 113
  • 1
  • 3
0
votes
1 answer

permission sp_xp_cmdshell_proxy_account for more than one user who needs to run xp_cmdshell without a sysadmin

I created a proxy account that xp_cmdshell will run using sp_xp_cmdshell_proxy_account And I gave one user permission EXEC sp_xp_cmdshell_proxy_account 'Domain\user1' If I give another user too EXEC sp_xp_cmdshell_proxy_account 'Domain\user2' I…