Windows 10: How to: Execute DOS commands from T-SQL

Discus and support How to: Execute DOS commands from T-SQL in Windows 10 Tutorials to solve the problem; Sometimes you might have the need to execute a copy, delete or run a batch file from a stored procedure. This can be done by using the xp_cmdshell and... Discussion in 'Windows 10 Tutorials' started by Noel, Jun 21, 2018.

  1. Noel New Member

    How to: Execute DOS commands from T-SQL


    Sometimes you might have the need to execute a copy, delete or run a batch file from a stored procedure. This can be done by using the xp_cmdshell and execute your command line.

    This can be done as below

    EXECUTE master..xp_cmdshell 'copy c:\test.txt c:\test1.txt'

    You can run it using parameters as below

    DECLARE @sql VARCHAR(200)
    SET @sql = 'copy c:\test.txt c:\test1.txt'
    EXECUTE master..xp_cmdshell @sql

    If you are running the xp_cmdshell and get the error "SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server." Follow the code below to enable the feature.

    EXEC sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    EXEC sp_configure 'xp_cmdshell', 1;
    GO
    RECONFIGURE;
    GO

    (32)

    read more...
     
  2. Brink Win User

    SQL Server Guidance against speculative execution vulnerabilities


    Source: https://support.microsoft.com/en-us/...for-sql-server
     
    Brink, Jun 21, 2018
    #2
  3. Execute a command from SCCM Task sequence step "Run a Command line"

    Hi,

    Thanks for your suggestion.

    That will work indeed, however I need to run it from the SCCM Task Sequence's Run Command Line Step and I am not able to figure out how to do that.

    Can we change line while executing command from SCCM Task Sequence's Run Command Line Step?

    Regards
     
    sccm_learner, Jun 21, 2018
    #3
  4. How to: Execute DOS commands from T-SQL

    SQL Error

    Am trying to reinstall SQL express and am getting below Error message.

    Error 27506, Error executing SQL script CreateDB. Line 27. CREATE DATABASE failed. Some file names listed could not be created. Check related errors. (1802)
     
    AmosMacharia Kamau, Jun 21, 2018
    #4
Thema:

How to: Execute DOS commands from T-SQL

Loading...
  1. How to: Execute DOS commands from T-SQL - Similar Threads - Execute DOS commands

  2. DOS Command Line maybe.

    in Windows 10 Gaming
    DOS Command Line maybe.: I have a directory with filenames “Photo001.jpg” thru “Photo099.jpg”. Using Windows 11.How can I easily add an “AV-“ prefix to each file name in the directory without changing anything else in the filename?Thanks...
  3. DOS Command Line maybe.

    in Windows 10 Software and Apps
    DOS Command Line maybe.: I have a directory with filenames “Photo001.jpg” thru “Photo099.jpg”. Using Windows 11.How can I easily add an “AV-“ prefix to each file name in the directory without changing anything else in the filename?Thanks...
  4. This program is dangerous and executes commands from an attacker

    in AntiVirus, Firewalls and System Security
    This program is dangerous and executes commands from an attacker: There are two particular programs that I have written for personal use in c# using Visual Studio. They go back years and I am always refining and adding new features. They sit on my computer and I have not developed them to talk across a network or any other sophisticated...
  5. Execution Command Save

    in Microsoft Windows 10 Store
    Execution Command Save: after execution Window Store missing command how will I save https://answers.microsoft.com/en-us/windows/forum/all/execution-command-save/f4fb6838-4af5-4c67-8821-ec6d6b8859de
  6. Execution Command Save

    in Windows 10 Gaming
    Execution Command Save: after execution Window Store missing command how will I save https://answers.microsoft.com/en-us/windows/forum/all/execution-command-save/f4fb6838-4af5-4c67-8821-ec6d6b8859de
  7. Execution Command Save

    in Windows 10 Software and Apps
    Execution Command Save: after execution Window Store missing command how will I save https://answers.microsoft.com/en-us/windows/forum/all/execution-command-save/f4fb6838-4af5-4c67-8821-ec6d6b8859de
  8. DOS format command

    in Windows 10 Network and Sharing
    DOS format command: DOS format command -- a few questions 1 Format /p:2 would do an initial sector zero-fill followed by 2 random fills. What's in a random fill? Is it a sector-long string of a single non-zero character, or a random string of different characters e.g. x'7f38e2 ...'? 2 Is there...
  9. DOS Command issued from Batch file

    in Windows 10 Network and Sharing
    DOS Command issued from Batch file: I have been running a batch file to list my personal file, and output the listing to a text file in a folder dv7. I then use the text file to compare to files on another computer or external drive, as backup. For some reason it no longer works. The command in the BAT file...
  10. Differences in format of DOS command results

    in Windows 10 Support
    Differences in format of DOS command results: OK, so I am doing some stuff in DOS, not geeky stuff but playing around. I have two computers that I can use, both with W10. So, I do a 'DIR' command, saving to a file, and then look at it. Then same again on the other computer. It annoys me that the format of the results...

Users found this page by searching for:

  1. how to run a java command from a sql server function?

    ,
  2. execute dos command in sql

    ,
  3. tsql exec dos command from proc

    ,
  4. set sql execute command,
  5. execute cmd from sql,
  6. how to run t-sql command,
  7. how to run windows command from SQL,
  8. how to run cmd commands in T-SQL,
  9. tsql how to run dos command,
  10. run dos command from tsql,
  11. sql dos commands,
  12. execute cmd command on sql,
  13. dos sql,
  14. using sql server agent to do dos file commands,
  15. how to run cmd command by t-sql