Run batch file from SQL

  • Hi,

    I know I can run a batch file with SQL Server using xp_cmdshell, but does anyone else know of a more secure way? In fact, the commands I'm running require that the user be a Domain Admin, and given that xp_cmdshell runs under the same account as SQL Server (which is not a Domain Admin account), I was hoping there'd be another way.

    Any ideas?

    Mike Scalise, PMP
    https://www.michaelscalise.com

  • I'd consider using CLR for this sort of thing, but you can run a batch file via SQL Agent as a scheduled job.

    The probability of survival is inversely proportional to the angle of arrival.

  • Under which user context would the CLR function be run?

    Mike Scalise, PMP
    https://www.michaelscalise.com

  • I prefer SQL Agent more Secure and best way. I am using SQL Agent to run batch File also.

  • Do you have any users on your server, other than "SA", that absolutely require "SA" privs for anything else other than xp_CmdShell usage?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (12/6/2011)


    Do you have any users on your server, other than "SA", that absolutely require "SA" privs for anything else other than xp_CmdShell usage?

    No, I do not.

    -Mike

    Mike Scalise, PMP
    https://www.michaelscalise.com

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

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