2016-04-11 54 views
1

が、私は次の行に実行するバッチファイルがあれば有効にします。.NET 3.5をチェックし、無効

dism /online /get-features /format:table | find "NetFx3" 

NetFx3は、私は、次のコマンドでそれを有効にする「無効」であると出力された場合には:

dism.exe /online /enable-feature /featurename:NetFX3 

実際に出力を照会して有効/無効をチェックする方法はわかりません。

+0

: は、出力文字列は次のようになりますか?これでスクリプトが壊れますか? – npocmaka

+0

奇妙なことに、私は 'enable'コマンドが既に有効になっている場合、それを実行することについて考えなかった。私はいくつかのデバイスでotをテストし、出力が何であるかを見ていきます。 – Rawns

答えて

1

ドットネットコードを使って簡単に行うことができます。 As、

  1. 適切な引数でDismプロセスを開始します。
  2. ShellExecuteを使用しないでください。
  3. リダイレクト標準出力。
  4. 標準出力を読み取ります。

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. 
+0

あなたは答えることができます。 –

関連する問題