2016-09-01 31 views
-3

这里有一些要求:Windows服务和调度管理使用Web应用程序

的applcation应该能统计,停止,启用和禁用服务/调度给定服务器上。

它应该能够给定服务器上创建新的调度和安装服务

请让我知道,如果有一种方法可以实现这些使用Web应用程序。

+0

@ A.T。他们真的不应该 – jonrsharpe

回答

0

这不容易做到。您需要为安装和卸载服务创建单独的.bat文件。与需要为启动/停止/启用/禁用功能创建单独的.bat文件相同。

好吧,使用System.Diagnostics.Process对象和静态方法从ASP.NET运行.BAT文件应该很简单吧?那么,这可能适用于你,但它肯定不会在我的机器上工作。在对这个问题做了大量的研究之后,其他人也似乎也遇到了问题。

我与权限和各种其他的东西摔跤,试图获得一个简单的批处理文件运行,没有运气。我尝试直接启动bat文件,启动cmd.exe并使用stin调用bat文件。没有骰子。看来我的机器上有一些东西是保持无人值守的过程来运行bat文件。这是有道理的,但我永远无法确定是什么阻止了这一点,所以我想出了一个解决方法。

我意识到,因为我可以成功运行cmd.exe,并通过stin发送命令给它,我可以打开批处理文件,并将每行发送到cmd.exe,这与运行批处理基本相同文件本身。这种技术很好,我想我会在这里传递代码。

// Get the full file path 
string strFilePath = “c:\\temp\\test.bat”; 


// Create the ProcessInfo object 
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(“cmd.exe”); 
psi.UseShellExecute = false; 
psi.RedirectStandardOutput = true; 
psi.RedirectStandardInput = true; 
psi.RedirectStandardError = true; 
psi.WorkingDirectory = “c:\\temp\\“; 


// Start the process 
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi); 



// Open the batch file for reading 
System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath); 


// Attach the output for reading 
System.IO.StreamReader sOut = proc.StandardOutput; 


// Attach the in for writing 
System.IO.StreamWriter sIn = proc.StandardInput; 



// Write each line of the batch file to standard input 
while(strm.Peek() != -1) 
{ 
    sIn.WriteLine(strm.ReadLine()); 
} 


strm.Close(); 


// Exit CMD.EXE 
string stEchoFmt = “# {0} run successfully. Exiting”; 


sIn.WriteLine(String.Format(stEchoFmt, strFilePath)); 
sIn.WriteLine(“EXIT”); 


// Close the process 
proc.Close(); 


// Read the sOut to a string. 
string results = sOut.ReadToEnd().Trim(); 



// Close the io Streams; 
sIn.Close(); 
sOut.Close(); 



// Write out the results. 
string fmtStdOut = “<font face=courier size=0>{0}</font>”; 
this.Response.Write(String.Format(fmtStdOut,results.Replace(System.Environment.NewLine, “<br>”))); 

就是这样!奇迹般有效!

+0

首先感谢很多快速响应... 在这里我有一个小小的怀疑是,我有这么多的服务器,所以我想访问调度/服务基于服务器ips /名称作为应用程序中的输入..但事情是我不想安装或承载这些web应用程序在所有的服务器上执行服务器端的进程..作为应用程序将在客户端执行我怎样才能管理访问所有服务器使用单个应用程序托管在其他服务器..我不知道我的问题是否有效...请让我知道,如果有任何转身为此... 再次感谢... –

相关问题