Jump to content

Recommended Posts

Posted

Hi, I've get an error after calling of IUpdate2::CopyToCache() method in my

program. I trying to install windows updates (*.msu) at Windows Vista x86

with .NET program using WUA (as Interop.WUApiLib). My Code:

----------------------------------------------------

using System;

using System.Collections.Generic;

using System.IO;

using System.Diagnostics;

using WUApiLib;

namespace WUApiLibTest

{

static class Program

{

[sTAThread]

static void Main()

{

// Update File: C:\Windows6.0-KB123456-x86.msu

// Emoty Directory: C:\ExpandedUpdate\

Process expandProcess = new Process();

expandProcess.StartInfo.FileName = "Expand";

expandProcess.StartInfo.WorkingDirectory = @"C:\";

expandProcess.StartInfo.Arguments =

@"C:\Windows6.0-KB123456-x86.msu -f:WSUSSCAN.cab C:\ExpandedUpdate\";

expandProcess.Start();

expandProcess.WaitForExit();

UpdateSessionClass updateSession = new UpdateSessionClass();

IUpdateServiceManager updateServiceManager =

updateSession.CreateUpdateServiceManager();

IUpdateService updateService =

updateServiceManager.AddScanPackageService("Offline Sync Service",

@"C:\ExpandedUpdate\WSUSSCAN.cab", 0);

IUpdateSearcher updateSearcher =

updateSession.CreateUpdateSearcher();

updateSearcher.ServerSelection = ServerSelection.ssOthers;

updateSearcher.ServiceID = updateService.ServiceID;

ISearchResult searchResult =

updateSearcher.Search("Type='Software'");

if (searchResult.Updates.Count > 0)

{

expandProcess.StartInfo.Arguments =

@"C:\Windows6.0-KB123456-x86.msu -f:Windows*.cab C:\ExpandedUpdate\";

expandProcess.Start();

expandProcess.WaitForExit();

StringCollectionClass filesToCopy = new

StringCollectionClass();

foreach (string fileName in

Directory.GetFiles(@"C:\ExpandedUpdate\", "Windows6.0-*.cab"))

filesToCopy.Add(fileName);

UpdateCollectionClass updateCollection = new

UpdateCollectionClass();

updateCollection.Add(searchResult.Updates[0]);

IUpdate2 iUpdate2 = (IUpdate2)searchResult.Updates[0];

// BUGGY LINE

iUpdate2.CopyToCache(filesToCopy);

// COMException (HRESULT: 0x80240026)

// 0x80240026 - WU_E_INVALID_UPDATE_TYPE

// ... updateInstaller etc.

}

}

}

}

----------------------------------------------------

Help me, please...

Best regards, Alexander Kozlenko

P.S. Sorry for my bad english.


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...