2011-07-19 12 views
3

ここでは、WUA COMインターフェイス(IUpdateSearcherIUpdateなど)を使用するアプリケーションを記述しました。私はこのアプリケーションを使用して、利用可能なアップデートをスキャンし、アップデートをダウンロードしてインストールします。私がダウンロードしていくつかのアップデートをインストールし、いくつかのアップデートダイアログをインストールするまで、すべて正常に動作します。 を使用したときにこのアップデートを取得しましたが、それを正常にダウンロードできます(IUpdateDownloader.Download()を使用しています)。IUpdateInstaller2.Install()を使用してこのアップデートをインストールすると、ユーザーインターフェイスを削除できません。windows update application

私の質問は - 私はこれをサイレントインストールにすることができますか?

+0

私の好奇心のために、なぜあなたはそのようなアプリケーションを書いているのですか? – Johnny5

+0

それは多くのPC上で制御する大きなシステムの一部です(オプションの1つは、eche PCのWindowsアップデートを制御することです...) – confi

+1

解決策を見つけるIUpdateInstaller2 instend IUpdateInstaller、 "forcesielte"プロパティがあります... – confi

答えて

3
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using WUApiLib; 
namespace MSHWindowsUpdateAgent 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      UpdatesAvailable(); 
      EnableUpdateServices();//enables everything windows need in order to make an update 
      InstallUpdates(DownloadUpdates()); 
      Console.Read(); 
     } 
     //this is my first try.. I can see the need for abstract classes here... 
     //but at least it gives most people a good starting point. 
     public static void InstalledUpdates() 
     { 
      UpdateSession UpdateSession = new UpdateSession(); 
      IUpdateSearcher UpdateSearchResult = UpdateSession.CreateUpdateSearcher(); 
      UpdateSearchResult.Online = true;//checks for updates online 
      ISearchResult SearchResults = UpdateSearchResult.Search("IsInstalled=1 AND IsHidden=0"); 
      //for the above search criteria refer to 
      //http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx 
      //Check the remakrs section 

      foreach (IUpdate x in SearchResults.Updates) 
      { 
       Console.WriteLine(x.Title); 
      } 
     } 
     public static void UpdatesAvailable() 
     { 
      UpdateSession UpdateSession = new UpdateSession(); 
      IUpdateSearcher UpdateSearchResult = UpdateSession.CreateUpdateSearcher(); 
      UpdateSearchResult.Online = true;//checks for updates online 
      ISearchResult SearchResults = UpdateSearchResult.Search("IsInstalled=0 AND IsPresent=0"); 
      //for the above search criteria refer to 
      //http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx 
      //Check the remakrs section 

      foreach (IUpdate x in SearchResults.Updates) 
      { 
       Console.WriteLine(x.Title); 
      } 
     } 
     public static UpdateCollection DownloadUpdates() 
     { 
      UpdateSession UpdateSession = new UpdateSession(); 
      IUpdateSearcher SearchUpdates = UpdateSession.CreateUpdateSearcher(); 
      ISearchResult UpdateSearchResult = SearchUpdates.Search("IsInstalled=0 and IsPresent=0"); 
      UpdateCollection UpdateCollection = new UpdateCollection(); 
      //Accept Eula code for each update 
      for (int i = 0; i < UpdateSearchResult.Updates.Count; i++) 
      { 
       IUpdate Updates = UpdateSearchResult.Updates[i]; 
       if (Updates.EulaAccepted == false) 
       { 
        Updates.AcceptEula(); 
       } 
       UpdateCollection.Add(Updates); 
      } 
      //Accept Eula ends here 
      //if it is zero i am not sure if it will trow an exception -- I havent tested it. 

       UpdateCollection DownloadCollection = new UpdateCollection(); 
       UpdateDownloader Downloader = UpdateSession.CreateUpdateDownloader(); 

       for (int i = 0; i < UpdateCollection.Count; i++) 
       { 
        DownloadCollection.Add(UpdateCollection[i]); 
       } 

       Downloader.Updates = DownloadCollection; 
       Console.WriteLine("Downloading Updates"); 
       IDownloadResult DownloadResult = Downloader.Download(); 
       UpdateCollection InstallCollection = new UpdateCollection(); 
       for (int i = 0; i < UpdateCollection.Count; i++) 
       { 
        if (DownloadCollection[i].IsDownloaded) 
        { 
         InstallCollection.Add(DownloadCollection[i]); 
        } 
       } 
       return InstallCollection; 
     } 
     public static void InstallUpdates(UpdateCollection DownloadedUpdates) 
     { 
      UpdateSession UpdateSession = new UpdateSession(); 
      UpdateInstaller InstallAgent = UpdateSession.CreateUpdateInstaller() as UpdateInstaller; 
      InstallAgent.Updates = DownloadedUpdates; 

      //Starts a synchronous installation of the updates. 
      // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386491(v=VS.85).aspx#methods 
      IInstallationResult InstallResult = InstallAgent.Install(); 

     } 
     public static void EnableUpdateServices() 
     { 
      IAutomaticUpdates updates = new AutomaticUpdates(); 
      if (!updates.ServiceEnabled) 
      { 
       Console.WriteLine("Not all updates services where enabled. Enabling Now" + updates.ServiceEnabled); 
       updates.EnableService(); 
       Console.WriteLine("Service enable success"); 
      } 


     } 

    } 
} 
0

jvelezは、優れた答えを持っていますが、それは直接、実際の質問に答えるしません:「?どのように私はこのサイレントinstaltion行うことができます」と

static class Program 
{ 
/// <summary> 
/// The main entry point for the application. 
/// </summary> 
[STAThread] 
static void Main() 
{ 
Application.SetCompatibleTextRenderingDefault(false); 
Application.EnableVisualStyles(); 

Thread thread = new Thread(() => 
{ 
Form1 form1 = new Form1(); 
form1.Visible = false; 
form1.ShowInTaskbar = false; 
Application.Run(form1); 
}); 

thread.SetApartmentState(ApartmentState.STA); 
thread.Start(); 
} 
} 

確保すべてのメソッドは、単にあなたのUIを非表示にすることで、バックグラウンドで働いていた、これはあなたにそれがサイレント作るの手段を与える: -

CONFI私が最初に最も簡単な方法をお勧めします。

@Justin Choponis - 私はconfiと同じようにする必要があります。 WSUSは私のクライアントの多くにとってそれをカットしていません。そのimpraticalとかさばる。あなたが見て、オンサイトになっていたネットワークが1つあれば、WSUSはそれ以外の場合には役に立たないと私は非常に満足できないと感じています。