How to execute xp_cmdshell

  • Hi

    How to execute the xp_cmdshell procedure in Sql Server 2005

    Thanks and Regards

    Suresh

  • you need to allow xp_cmdshell in SQL 2005.

    Its in the Surface Area management. Then it should be

    Example

    EXEC xp_cmdshell 'dir "c:\"'

  • You have to Enable the xp_cmdshell from

    Surface Area Configuration --> Surface Area Configuration for Features.

    Complete syntax is ;

    xp_cmdshell { 'command_string' } [ , no_output ]

    command_string can be any DOS based command.

    no_output is specified if you donot want any output fgrom the DOS command after execution (for example, Copy command).

    Check:

    http://msdn.microsoft.com/en-us/library/ms175046.aspx">

    http://msdn.microsoft.com/en-us/library/ms175046.aspx

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • Looks like this

    exec master.dbo.xp_cmdshell 'dir c:\temp\*.sql'

    you can pretty much do anything you like

    for exp

    exec master.dbo.xp_cmdshell 'copy c:\ted.txt h:\ted.txt'

    and so on

    Terry

  • As an alternative, you can also enable xp_cmdshell in code by running the following:

    exec sp_configure 'xp_cmdshell', 1

    Reconfigure

    Bob Pinella

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply