ドットネットコードを使って簡単に行うことができます。 As、
- 適切な引数でDismプロセスを開始します。
- ShellExecuteを使用しないでください。
- リダイレクト標準出力。
- 標準出力を読み取ります。
Vb.netコード:
Public Function GetDismOutput() As String
Dim Output As String = Nothing
Dim SxsPath As String = "D:\Sources\sxs"
Dim CmdParm As String = "/online /enable-feature /featurename:NetFX3 /All /Source:"""
Dim Pinf As New ProcessStartInfo With {.FileName = SxsPath, .Arguments = CmdParm + SxsPath + """ /LimitAccess"}
Dim Prc As Process
Try
Pinf.UseShellExecute = False
Pinf.RedirectStandardOutput = True
Prc = Process.Start(Pinf)
Prc.WaitForExit(20 * 60 * 1000) '' Wait for 20 Minutes
CmdParm = Prc.StandardOutput.ReadToEnd()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return Output
End Function
C#コード:ソースの\ SXS \ SXSフォルダのパスです:Dは
public string GetDismOutput()
{
string Output = null;
string SxsPath = "D:\\Sources\\sxs";
string CmdParm = "/online /enable-feature /featurename:NetFX3 /All /Source:\"";
ProcessStartInfo Pinf = new ProcessStartInfo {FileName = SxsPath, Arguments = CmdParm + SxsPath + "\" /LimitAccess"};
Process Prc = null;
try
{
Pinf.UseShellExecute = false;
Pinf.RedirectStandardOutput = true;
Prc = Process.Start(Pinf);
Prc.WaitForExit(20 * 60 * 1000); //' Wait for 20 Minutes
CmdParm = Prc.StandardOutput.ReadToEnd();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return Output;
}
。確認せずにNetFX3`:あなたが直接 `dism.exe /オンライン/イネーブル機能/ FEATURENAMEを何を実行した場合
Deployment Image Servicing and Management tool
Version: 6.3.9600.17031
Image Version: 6.3.9600.17031
Enabling feature(s)
The operation completed successfully.
: は、出力文字列は次のようになりますか?これでスクリプトが壊れますか? – npocmaka
奇妙なことに、私は 'enable'コマンドが既に有効になっている場合、それを実行することについて考えなかった。私はいくつかのデバイスでotをテストし、出力が何であるかを見ていきます。 – Rawns