Solved

How do I run a xp_cmdshell  batch file as a different user?

Posted on 2008-10-30
4
1,495 Views
Last Modified: 2008-11-27
I have a stored procedure that runa a batch file. The batchfile uses GPG to decrypt a file.  When run the batch file from Explorer everything works. The keys for the decryption are installed under another user account that requires a password.  However when I execute the stored procedure the batch file does not work.  I am assuming that SQL SERVER executes the stored procedure as a sysadmin account therefore not allowing the batch file to execute properly.  How can I accomplish getting this to work.

      SET @cmdSql = ' EXEC xp_cmdshell C:\Batch\Decrypt_EmailCleansingList.bat'      
      EXEC sp_executesql @cmdSql

       gpg --batch --decrypt-files C:\RawData\*.pgp
      
0
Comment
Question by:klyles95
4 Comments
 
LVL 4

Accepted Solution

by:
randy_knight earned 63 total points
ID: 22843636
xp_cmdshell runs in the security context of the service account SQL Server is running under.  I'm not aware of a way to change this.  Do you have to run this from a proc?  Can you run the batch file from a SQL Server Agent job?  That will run under the security context of the job owner.
0
 
LVL 6

Assisted Solution

by:bcsql
bcsql earned 62 total points
ID: 22845497
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server Log File Space 6 34
sql query Help 12 34
Stored procedure 23 24
DATETIMEOFFSET feature 1 0
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now