![]() |
| How to Execute a .bat file in .NET |
|
Jason101
Forum Regular
|
OK, heres the deal. I don't know a thing about .net. I searched the net for a few hours, and couldn't find what what I needed.
Here's what I'm trying to accomplish. I want to execute a .bat file on my server that will restart the ColdFusion 8 service. The bat file is created and works. So that's not the issue. I just need help executing it with.Net. (I could have used <cfexecute> in cf8, but if the ColdFusion service is down what good does that do me) I found this snippet on a blog that will do what I need it to (I think) http://axdimensions.wordpress.com/2008/02/07/run-a-bat-file-from-net-with-parameters/ But I have no clue how to call the page, function or anything. Would someone who is .net savvy mind getting me started with a simple page? I'd hope to return the favor if that person ever needs CF help Oh yeah.. I'm not on a Shared Server so no worries about execute permissions. I'm running Server 2008 & IIS7 Thanks in advance! |
||||||||||||
|
|
|||||||||||||
|
rcorbin
|
does it have to be .net? I know you can do it with regular ASP...I've done it with something like
Though there are some permissions that need changed...I think the default app pool wont have permission..I think i had to change it to 'local system' and made sure the web entry could run scripts and executables? Something like that...let me know if you cant get it working. This is for 2003 and iis 6.0 -Ray |
||||||||||||||
|
|
|||||||||||||||
| How about this? |
|
jholbrook
|
You could use System.Diagnostics.Process and call the command you desire directly, however you will need to ensure that the account your application is running as has permission to do so, and also consider the security implications of elevating the account. Here is a simple example of calling a shell command from the code-behind.
'Declarations Imports System.Diagnostics.Process Dim p As Diagnostics.Process = New Diagnostics.Process p.StartInfo.FileName = "C:\Windows\System32\cmd.exe" ' this is the name of the process we want to execute p.StartInfo.Arguments = "/C net start ""Coldfusion 8 Application Server""" 'Arguments to pass to the shell p.StartInfo.UseShellExecute = False 'Used to allow us to get output below p.StartInfo.RedirectStandardOutput = True 'Used to allow us to get output below p.Start() ' start the process Dim output As String = p.StandardOutput.ReadToEnd 'get output p.WaitForExit() 'wait for completion This is in VB.net you can convert it here if you use C#: http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx Let me know how it works out, or if you need another example. |
||||||||||||
|
|
|||||||||||||
| How to Execute a .bat file in .NET |
|
||
|


