2010-07-16 79 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,或者一個簡單的註冊表項。但我認爲這隻適用於「常規」用戶 - 而不是內置的系統用戶。