2010-07-16 43 views
0

我想在asp.net页面上运行一些代码之后使用SDelete。 SDelete是一个命令行工具。我的具体问题是任何人都可以从asp.net页面运行这个SDelete吗?更通用的问题是,如何从asp.net页面运行命令行实用程序?SDelete从asp.net调用页面

感谢

回答

1

您可以使用Process Class

Process myProcess = new Process(); 

myProcess.StartInfo.UseShellExecute = false; 
// You can start any process, HelloWorld is a do-nothing example. 
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"; 
myProcess.StartInfo.CreateNoWindow = true; 
myProcess.Start(); 

再举一个例子接近asp.net,我等待结束运行命令行实用程序,读取输出。

 Process compiler = new Process(); 

     compiler.StartInfo.FileName = "c:\\hello.exe"; 

     compiler.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; 

     compiler.StartInfo.UseShellExecute = false; 
     compiler.StartInfo.CreateNoWindow = false; 

     compiler.StartInfo.RedirectStandardError = true; 
     compiler.StartInfo.RedirectStandardOutput = true; 
     compiler.StartInfo.RedirectStandardInput = true; 

     // here I run it 
     compiler.Start(); 

     compiler.StandardInput.Flush(); 
     compiler.StandardInput.Close(); 

     // here I get the output 
     string cReadOutput = compiler.StandardOutput.ReadToEnd(); 

     compiler.WaitForExit(); 
     compiler.Close(); 
1

Aristos的答案将适用于用户权限正常且SysInternals EULA被确认的情况。据此,我的意思是SysInternals的sdelete.exe实用程序将在IIS中分配的Asp.Net帐户下运行。如果该帐户没有适当的权限并且未接受弹出的EULA,则该文件不会被删除。我现在正面临着这个问题。

您可以指定用于运行过程中的域/用户/密码。也就是说这里概述: http://social.msdn.microsoft.com/Forums/hu-HU/netfxbcl/thread/70b2419e-cb1a-4678-b2ae-cedcfe08d06f 该线程的作者也有类似的问题,他澄清了通过改变sdelete.exe文件的所有权。

此线程也有关于登录所使用的执行过程中,用户并接受Sysinternals的EULA的一些信息: sdelete.exe is not working with cfexecute

但是,如果你打算使用是不可行的ASP内建。 Net系统帐户,因为这些用户帐户不允许使用typ登录。我可能会被迫创建一个单独的用户,我可以登录并接受EULA,然后指定这些凭据来运行该过程。不过在我的情况下,我可能没有选择在我的生产服务器上创建用户的选项。

有办法迫使EULA接受命令行PARAM,或者一个简单的注册表项。但我认为这只适用于“常规”用户 - 而不是内置的系统用户。