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
1 answer

bcp export data to txt having arabic filename

I'm trying to export data to txt file having arabic filename using xp_cmdshell It is working fine. the problem is when I tried to name the file in arabic i got this error message SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Server…
0
votes
1 answer

SQL Server Log File

I have a little issue about logging files. I want to export this string called test, but i dont know why i cant do that. I know that command_string should not have more than 8000 characters. I don't understand why this doesn't work. Can anyone help…
ePascoal
  • 2,362
  • 6
  • 26
  • 44
0
votes
3 answers

Unable to delete zip files from DB server location using xp_cmdshell

I have a Zip file created and I am unable to delete it using the below command. xp_cmdshell 'rm "F:\EXIS\Reports\Individual.zip"' It gives an error saying File not found, when I can actually see the file. I tried using xp_cmdshell 'del…
Pavan Kumar
  • 463
  • 2
  • 10
  • 18
0
votes
1 answer

EXEC MASTER.DBO.XP_CMDSHELL MOVE

I am working on a FILE that I need to move from one loacation to another, but when I run the code below I keep getting an error that it has the incorrect syntax. When I print the @Move statement I get this: (Which is what I think I should get) MOVE…
user2084896
  • 33
  • 1
  • 1
  • 5
0
votes
1 answer

xp_cmdshell execute assembly and never stops

I wrote some console application and I want execute it through Sql Server using xp_cmdshell. So I wrote the following query: declare @sqlcmd varchar(200) SET @SQLCmd = 'C:\Automation\ProfileCreator\ProfileManagement.exe ' + @someParameter EXEC…
Ofir
  • 5,049
  • 5
  • 36
  • 61
0
votes
1 answer

tsql get the time stamp of files in a folder without using xp_cmdshell

I can't use xp_cmdshell due to security reason. Is there another way to get the time stamp of files in a folder without using xp_cmdshell? Thanks!
To Do
  • 151
  • 11
0
votes
1 answer

copy-item using xp_cmdshell in SQL Server

I'm trying to send the "copy-item" command using xp_cmdshell to move an item I encrypt earlier in a sproc. In the sproc I create a .bat file, executed as a scheduled task, to do the encryption. I've tried using the same method to execute the…
Gabe N.
  • 11
  • 7
0
votes
2 answers

command 'exec master..xp_cmdshell' does not creating file

I'm not getting success with this command DECLARE @cmd sysname, @var sysname SET @var = 'Hello world' SET @cmd = 'echo ' + @var + ' > C:\var_out.txt' EXEC master..xp_cmdshell @cmd Already tried several examples, but it did not work. The command…
msantiago
  • 346
  • 2
  • 4
  • 14
0
votes
1 answer

XP_CMDSHELL how to capture return value?

I need to write an console application that returns a return code that can be captured through xp_cmdshell. I started with c# code as follows, class Program { static int Main(string[] args) { //make sure the correct…
user2206329
  • 2,792
  • 10
  • 54
  • 81
0
votes
1 answer

Using window commands to delete the first two lines of a text file

Can anyone provide a windows command or batch script that will remove the top two rows from a text file? I'd like to remove the first two lines of a text file using findstr. I can't use the "more +2 file.txt > newfile.txt" trick described here…
FistOfFury
  • 6,735
  • 7
  • 49
  • 57
0
votes
1 answer

Access denied when xcopying using xp_cmdshell

I have the ff: scenario, I have two servers, 1 outside(ServerB), 1 inside a domain(ServerA) ServerA has an sp that uses xp_cmdshell to call a batch file from ServerB Inside the batch file is an "XCOPY", when I execute the stored procedure I'm…
mirageservo
  • 2,387
  • 4
  • 22
  • 31
0
votes
1 answer

Stored procedure with EXECUTE AS cannot run xp_cmdshell

I have a sql server user, proxyAccount, which I configured as xp_cmdshell_proxy_account In a stored procedure I use xp_cmdshell, and when I execute the stored procedure with this account, everything works fine. However, if I add: WITH EXECUTE AS…
ANisus
  • 74,460
  • 29
  • 162
  • 158
0
votes
1 answer

xp_cmdshell queryout is generating a Excel file correctly but with ONE blank line in the middle of the file

I have a stored procedure that runs once at the end of every month. It generates a few files. One of them is a .csv file. SELECT @Command = 'bcp "EXEC DB1.dbo.spCreateFile" queryout "' + @LocalFilePath + @MainFileName + '" -c -T -x' EXEC…
JJ.
  • 9,580
  • 37
  • 116
  • 189
0
votes
1 answer

What is the most secure way to allow users to execute BCP export command from SQL?

I am currently working in an environment where the ability to export a table programatically from within a hand-run SQL script would be of great help. Performing the exports from script will be the first step towards running the entire process…
samaspin
  • 2,342
  • 1
  • 26
  • 31
0
votes
2 answers

SQL Server : xp_cmdshell have very limited privilegies

I don't know if it should be like this. When I'm trying to do anything with xp_cmdshell procedure it almost every time gives me Access Denied. For example I can't create new .txt file, can't create new user, nothing. I'm logged in with windows…
1 2 3
17
18