在C#中,我該如何檢查設備和系統錯誤?使用PowerShell Scipts會很簡單,還是會增加複雜性和難度?C# - 檢查設備問題和系統問題
回答
對於Windows 7客戶請查看Windows Troubleshooting Platform。這裏有一個download上面有更多的細節。它使用PowerShell腳本來完成你正在談論的內容。這blog post顯示如何撰寫故障排除包 - 這很容易。
我不認爲WTP適用於下層平臺。在這種情況下,我只需編寫一些PowerShell腳本來檢測並修復根本原因。如果你想把它包裝在一個漂亮的用戶界面中,請查看PowerBoots - 在腳本之上創建一個WPF GUI的簡單方法。如果你想在你的基於C#的GUI上託管PowerShell,那很簡單。以下是Forms應用程序的代碼片段:
private void button1_Click(object sender, EventArgs e)
{
string cmd = @"Get-ChildItem $home\Documents -recurse | " +
"Where {!$_.PSIsContainer -and " +
"($_.LastWriteTime -gt (Get-Date).AddDays(-7))} | " +
"Sort Fullname | Foreach {$_.Fullname}";
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
using (Pipeline pipeline = runspace.CreatePipeline(cmd))
{
this.Cursor = Cursors.WaitCursor;
pipeline.Commands.AddScript(cmd);
Collection<PSObject> results = pipeline.Invoke();
foreach (PSObject obj in results)
{
listBox1.Items.Add(obj);
}
this.Cursor = Cursors.Default;
}
}
}
您需要添加對System.Management.Automation程序集的引用。如果您已安裝應在ProgramFiles \ ReferenceAssemblies \ Microsoft \ WindowsPowerShell \ v1.0中的Windows/.NET SDK。您還需要使用狀態圖:
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
我很想在我的GUI中獲得一些Powershell。我可以在哪裏與您聯繫? – Michael 2009-10-14 15:57:27
你可以通過我的博客http://KeithHill.spaces.live.com與我聯繫 – 2009-10-14 17:52:12
- 1. c#插件系統問題
- 2. UWP/C# - AQS和USB設備問題
- 3. 問題訪問iOS設備
- 4. 問題與投票系統,Cookie問題
- 5. 粘性系統 - 問題 - 問題
- 6. SFML輸入系統問題
- 7. 入侵檢測系統,安全+問題
- 8. C#拼寫檢查問題
- 9. Android設備問題
- 10. 問題與設備
- 11. 系統問題()調用
- 12. 設計問題:預訂系統
- 13. 一個系統設計問題
- 14. 的通知系統設計問題
- 15. 系統設計面試問題
- 16. 標記系統設計問題
- 17. 統一C#問題
- 18. Firefox操作系統設備圖形問題
- 19. C++ Windows鏈接子系統問題
- 20. C#動態DLL系統問題
- 21. C++系統調用安全問題
- 22. C#報警系統迴路問題
- 23. C++中的系統調用問題
- 24. MySQL查詢問題:像系統預訂
- 25. 查詢問題排名系統MYSQL
- 26. BLOG系統SQL summery查詢問題
- 27. fork和wait系統調用問題
- 28. 移動設備檢測問題
- 29. 關於檢測USB設備的問題
- 30. 設備未檢測到Ubislate 7ci問題
您能說清楚「設備和系統錯誤」是什麼意思嗎?哪些設備和系統? – bobbymcr 2009-10-14 03:28:25
沒有特定的錯誤,只是一般的錯誤。也許可以檢測到設備可能失敗的可能原因。我可以手動執行此操作,但是它適用於其他用戶,所以爲了讓生活變得更輕鬆,可能會檢測一些可能的原因並將其顯示給用戶。 – Michael 2009-10-14 03:40:54