Solved

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

Posted on 2008-10-30
4
1,613 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

832 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