Solved

deleting a file with SQL xp_cmdshell

Posted on 2014-09-24
3
162 Views
Last Modified: 2014-09-24
Hello experts,

I am running this one line code on SQL Management Console and it gets hung at 'Executing Query':

exec master..xp_cmdshell 'C:\Test1\Test2\test3.txt'

What is the issue? I login to the SQL Server as the local administrator of that (same) server. Is there something I am missing? Should the folder be shared instead and I use the share name?

Thank you in advance
0
Comment
Question by:bozer
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40340987
>exec master..xp_cmdshell 'C:\Test1\Test2\test3.txt'
this would only "open" the file (on the server, in the sql server login session, so unvisible except in the task manager)

to DELETE the file:


exec master..xp_cmdshell 'del C:\Test1\Test2\test3.txt'
0
 

Author Comment

by:bozer
ID: 40340990
I've requested that this question be deleted for the following reason:

Typo
0
 

Author Closing Comment

by:bozer
ID: 40340991
I just realized that after posting but you were even faster to reply Guy, thanks :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now