How to run a .bat file from asp.net in the server side

In asp.net we can use System.Diagnostics.Process class to run the .bat file but it is not allowed in IIS for some security purpose So we have
to use another way for running .bat file in server side.



System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo("D:/copy.bat");
p.Start();


Here is the another way to running .bat file in server side we can use sql server xp_cmdshell system define procedure to running .bat file.

1) First we have to enable  enable xp_cmdshell using sp_configure then execute our .bat file through xp_cmdshell.

The xp_cmdshell option is a server configuration option that enables system administrators to control whether the xp_cmdshell extended stored procedure can be executed on a system.




---- To allow advanced options to be changed.
EXEC sp_configure ‘show advanced options’, 1
GO
—- To update the currently configured value for advanced options.
RECONFIGURE
GO
—- To enable the feature.
EXEC sp_configure ‘xp_cmdshell’, 1
GO
—- To update the currently configured value for this feature.
RECONFIGURE
GO


EXEC MASTER..xp_cmdshell 'd:/copy.bat'

 



Recent Article