Few days back In my project I have to run a batch file which contains the series of piped MS-DOS commands to deals with Active Directory. Running batch file through ASP.NET requires impersonate the user id (for ASP.NET aspnet account), which requires lots of code and require understanding of windows securities.
I found one work around which is very easy and no need of extra coding.
In MS SQL Server there is one stored procedure named “xp_cmdshell” which executes a given command string as an operating-system command shell and returns any output as rows of text. i made a stored procedure and pass the batch file path as a parameter.
CREATE PROCEDURE RunBatchFile
@BatchFile varchar(1000)
AS
Create table #BatchResult (output varchar(1000))
Insert # BatchResult exec master..xp_cmdshell @BatchFile
Select output from # BatchResult
set noCount on
Drop table #OptInUserGroup
set noCount off
GO
I used SQL Server temporary table to get the result.
I hope it will help other guys who are searching “How to run batch file from ASP.NET”.
Related Post:
Association, Aggregation, Composition object relationship
Talent vs Attitude – Harsha Bhogle
What we can learn from Babies