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. sccm_learner Win User
    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. AmosMacharia Kamau Win User

    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. Windows 10 Power shell executes in command prompt

    in Windows 10 Customization
    Windows 10 Power shell executes in command prompt: I have been using power shell as an alternative to command prompt for quite a long time. I mostly use it for Android debugging tool "adb". I am recently facing problem where any command I write in Power Shell opens a cmd window, executes the command in cmd and closes the...
  3. Programatically execute remote commands from Linux server to Microsoft Windows server

    in Windows 10 Network and Sharing
    Programatically execute remote commands from Linux server to Microsoft Windows server: Apparently, there is no explicit way one can achieve this. I have a script on a windows server that I want to execute from a linux server programatically. Is it a supported use case for Windows? If so, can I get a code fragment that shows the same....
  4. Execute Powershell command on remote computer

    in Windows 10 Network and Sharing
    Execute Powershell command on remote computer: Hello, I would like to execute a PowerShell command on a remote computer. The command is the following: Invoke-Command -ComputerName 10.40.27.174 -ScriptBlock { Get-ChildItem C:\ } -credential User I get the following error: [10.40.27.174] La connexion au serveur...
  5. How to: Sync SQL users from one server to another

    in Windows 10 Tutorials
    How to: Sync SQL users from one server to another: When you have SQL Clustering with Always On, the databases are sycnhronised and the failover works like a charm. The only problem is that the logins are not synchronized from one server to another. To export the current users and import to another server, on the main server...
  6. How do i run cmd with commands already executed!

    in Windows 10 Support
    How do i run cmd with commands already executed!: OK say I wanted to run a cmd (I know I will have to use notepad so im pretty much asking the command and ending of the command ex. CMD.bat) For those that want to go ahead and be really helpful im looking to open cmd and do "color 4" Simple 99681
  7. SQL Server Guidance against speculative execution vulnerabilities

    in Windows 10 News
    SQL Server Guidance against speculative execution vulnerabilities: SQL Server Guidance to protect against speculative execution side-channel vulnerabilities Summary Microsoft is aware of a new publicly disclosed class of vulnerabilities referred to as “speculative execution side-channel attacks” that affect many modern processors and...
  8. 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...
  9. From DOS to the golden age of Windows

    in Windows 10 News
    From DOS to the golden age of Windows: Travelling back in time Those of us who grew up with computers have witnessed great change: from the hulking tower PCs of yore to the pocket-sized smartphones of today and from blinking green screen cursors to 4K graphical displays. For those old enough to remember...
  10. How To Create A Shortcut That Executes The "Undo" Command

    in Windows 10 Support
    How To Create A Shortcut That Executes The "Undo" Command: Hi, just a quick request. Does anyone know how to create a shortcut that I can open that will run the "Undo" command? For example: Suppose you have File Explorer open and delete a file from a folder. You can right click in that folder and click on "Undo Delete" to have...