xp_cmdshell is a Microsoft SQL Server extended stored procedure one can use to spawn a windows process to execute a command line. Questions in this tag should be about using this procedure.
Questions tagged [xp-cmdshell]
43 questions
11
votes
3 answers
"Unable to Open BCP host data-file" using xp_cmdshell from SSMS but command line works
I have a stored procedure that runs on a job every once in a while to BCP some files left by an application I've written.
I noticed the files were piling up and BCP wasn't picking them up so I tested in Management Studio using the…
Brandon
- 618
- 2
- 7
- 17
7
votes
2 answers
Why is script with " xp_cmdshell " in comment failing with a transport level error?
When executing the following batch that is part of a large script:
...
GO
-----------------------------------------------------------------------------------------------
-- Removed the xp_cmdshell for deleting the backup file…
Ed Greaves
- 181
- 5
6
votes
2 answers
problem running xp_cmdshell when Application Name set in connection string
I have an app on 10 or so servers that runs a few xp_cmdshell statements against MSSQL 2008. It works fine on all the servers except for one. To make things worse, I can run all the commands in SQL Management Studio, but in the app, they don't work.…
John Petrak
- 131
- 1
- 6
6
votes
2 answers
Can we minimise the risk of using xp_cmdshell?
Using xp_cmdshell can be quite helpful and sometimes possibly the only answer to some scenarios. I've read some posts on the internet that enabling xp_cmdshell might jeopardize the security of the database/server.
My question is that, is there…
Sky
- 3,744
- 18
- 53
- 68
5
votes
2 answers
xp_cmdshell called from procedure WITH EXECUTE AS OWNER
I am trying to understand details of wrapping xp_cmdshell functionality in user defined stored procs, so that other users can just be given execute permission to the stored procs rather than xp_cmdshell.
The steps in this scenario are:
xp_cmdshell…
John Rees
- 206
- 3
- 6
5
votes
3 answers
Invoke SQLCMD doesn't work when used with xp_cmdshell
I am trying to get disk space report from bunch of servers and insert them into sql table..
below is sample of what i am trying to do,Server names will be populated from a table and passed as a comma seperated list.Even passing one server also has…
TheGameiswar
- 2,999
- 4
- 30
- 50
5
votes
2 answers
How can I save the results of DBCC SHRINKFILE into a table?
I have the following script:
-- available space in each of the database files
PRINT @@SERVERNAME
--SQLDWDEV01
USE [BodenStage]
GO
SELECT name
,(CAST(ROUND((size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0),2) AS NUMERIC(18,2))) AS…
Marcello Miorelli
- 17,274
- 53
- 180
- 320
5
votes
3 answers
Execute xp_cmdshell as a non-windows user
So I have a bunch of database users who should be able to execute a procedure with a call to xp_cmdshell. They are not windows domain accounts, they are just sql-server logins. I want to do it using a proxy ##xp_cmdshell_proxy_account##. I am aware…
PacoDePaco
- 163
- 1
- 7
5
votes
6 answers
Alternative to xp_cmdshell for emailing a report as a CSV file
I've got an issue that I could do with some ideas as to how to achieve what's needed without using (or enabling) xp_cmdshell if possible.
I know that xp_cmdshell itself poses risks, even with a proxy account, however - in our environment it's…
Arkane
- 51
- 1
- 2
4
votes
1 answer
When executing a command via xp_cmdshell what user issues the command to the system?
I'm executing the following command to stop a service on a remote server from within a stored procedure in SQL Server.
----------------
-- Stop Service
----------------
SET @Command = 'sc \\' + @Server + ' stop ' + @ServiceName;
EXEC…
ProfessionalAmateur
- 515
- 2
- 8
- 18
3
votes
2 answers
how to get the date of a file using xp_cmdshell?
So far I've this code
CREATE TABLE #tmp (strData VARCHAR(1000))
INSERT INTO #tmp EXEC xp_cmdshell 'dir C:\Users\Giba\Desktop\Folder\cmdshell1\*.txt'
SELECT * FROM #tmp --WHERE strData LIKE '09/25/2018'
DROP TABLE #tmp
but I want to select only date…
Eola Giba
- 43
- 1
- 5
3
votes
3 answers
Is it safe to set xp_cmdshell value 1?
I need to use xp_cmdshell in one of SQL job.So is it safe to reconfigure xp_cmdshell to 1 or can i set value 1 in the starting of SQL statements and set it back to 0 in the end of SQL Statement ?
Rehan
- 73
- 2
- 10
3
votes
1 answer
"Access is denied." for xp_cmdshell for network share
On a SQL 2014 SP 1 instance a SQL Agent job I'm using xp_cmdshell to return a list of files from a network share. This has recently stopped working and returns "Access is denied."
The command is EXEC master..xp_cmdshell 'DIR…
tpet
- 1,214
- 10
- 15
3
votes
3 answers
CMDEXEC The process could not be created for step... (reason: Access is denied). The step failed
I have created a job to test executing a CmdExec step. The job step is simply executing a batch file with dir as the command.
The job is executing as the SQL Server service account. This account is both sysadmin of SQL Server and Administrator…
Don
- 305
- 1
- 2
- 10
2
votes
0 answers
SQL Server - Holistic approach to managing permissions from a domain
We are small IT department and we are changing how our infrastructure works. We are trying to make it more secure, manageable and transparent for auditing.
We are implementing a domain for our servers and possibly in the future for our…
AnJ
- 141
- 3
- 9