Solved

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

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

910 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

20 Experts available now in Live!

Get 1:1 Help Now