C# では、デバイスとシステムのエラーをチェックするにはどうすればよいですか? PowerShell Scipts を使用するのは簡単ですか? それとも、複雑さと困難さが増しますか?
1 に答える
Windows 7クライアントの場合は、Windowsトラブルシューティングプラットフォームを確認してください。詳細については、こちらからダウンロードしてください。PowerShellスクリプトを使用して、話していることを正確に実行します。このブログ投稿は、トラブルシューティングパックを作成する方法を示しています-それは非常に簡単です。
WTPはダウンレベルのプラットフォームでは機能しないと思います。この場合、根本的な原因を検出して修正するためのPowerShellスクリプトをいくつか作成します。それを素敵なUIにまとめたい場合は、PowerBootsをチェックしてください。スクリプトの上にWPFGUIを作成する簡単な方法です。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/.NETSDKをインストールした場合。また、statememetsをいくつか使用する必要があります。
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;