473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem understanding/using COM WAU API from C#[error:bad variabletype]

Hi All !

Sorry for my crossposting, I am not completely sure about which group is
really of any help. I started using the WUA [windows update agent] COM
API from C#. I created an interop assembly and my code compiles fine and
the most parts are running as expected.

I first create a UpdateSession object and look for updates, which are
downloaded. Then I create an UpdateInstaller, but this fails:

UpdateInstaller installer = (UpdateInstaller)
this.session.CreateUpdateInstaller(); //CRASH

I might have a wrong variable type here really. If I use VS's object
browser, I feel, I do not understand, why there are so many different
interfaces, like IUpdateInstaller, IUpdateInstaller2 etc.
I tried also:

IUpdateInstaller2 installer = (IUpdateInstaller2)
this.session.CreateUpdateInstaller(); //CRASH

May be, someone can help?

Thanks so far and
best regards,
Manfred

I append a repro here [hopefully, this is readable]

/*

Name: DemoComError.cs
Compile: csc /nologo /debug:full /t:exe /out:DemoComError.exe
/r:Interop.WUAApiLib.dll /r:log4net.dll DemoComError.cs
TLBIMP: TLBIMP /out:Interop.WUAApiLib.dll /namespace:Interop.WUALib
C:\WINDOWS\system32\wuapi.dll
TlbImp warning: At least one of the arguments for
'UpdateInstaller.get_ParentHwnd' can not be marshaled by the runtime
marshaler. Such arguments will therefore be passed as a pointer and
may require unsafe code to manipulate.
Error:
Unhandled Exception: System.Runtime.InteropServices.COMException
(0x80020008): Bad variable type.
at Interop.WUALib.IUpdateSession2.CreateUpdateInstall er()
at AdminTools.WindowsUpdateInfo.InstallUpdates() in
d:\Develop\Dev\Experimente\WSUS\Net\WUAWrapper\Dem oComError.cs:line 87
*/
using System;
using System.Runtime.InteropServices;
using Interop.WUALib;
namespace AdminTools
{

public class WUAApp
{
public static void Main(string[] args)
{
if(args.Length != 0)
{
WindowsUpdateInfo wui = new WindowsUpdateInfo(args[0]);
int count = wui.DetectUpdates(); //condition...
if(count != 0) wui.InstallUpdates();
}
else
{
Console.WriteLine("Args!!! [p1=computer]");
}
}
}//class

public class WindowsUpdateInfo
{
private string computerName;
private UpdateSession session;
private UpdateCollection updates;

public WindowsUpdateInfo(string computerName)
{
this.computerName = computerName;

try
{
Type type = Type.GetTypeFromProgID("Microsoft.Update.Session",
computerName, true);
this.session = (UpdateSession) Activator.CreateInstance(type);
}
catch(COMException ce)
{
Console.WriteLine("COMException;Exception:{0},Code :{1}", ce.Message,
ce.ErrorCode);
}
}

public int DetectUpdates()
{
IUpdate u;

IUpdateSearcher us = session.CreateUpdateSearcher();
ISearchResult sr = us.Search("IsInstalled=0 and Type='Software'");
this.updates = sr.Updates;
for(int i = 0; i < this.updates.Count; i++)
{
u = this.updates[i]; //do something with update;show.
}
Console.WriteLine("Updates:{0}", this.updates.Count);

return this.updates.Count;
}

public void InstallUpdates()
{
UpdateCollection updates = new UpdateCollection();
for(int i = 0; i < this.updates.Count; i++)
{
updates.Add(this.updates[i]);
}

Console.WriteLine("Added {0} updates to install.", updates.Count);

UpdateInstaller installer = (UpdateInstaller)
this.session.CreateUpdateInstaller(); //(87)CRASH
installer.Updates = updates;
IInstallationResult installationResult = installer.Install();

for(int i = 0; i < updates.Count; i++)
{
Console.WriteLine("Installed:{0},Result:{1}.", updates[i].Title,
installationResult.GetUpdateResult(i).ResultCode);
}

}

}//class

}//namespace
Oct 29 '06 #1
1 5559
Worked part of my code for using WUA (C#), may be help you:

UpdateSessionClass updateSession = new UpdateSessionClass();
UpdateServiceManagerClass updateServiceManager = new
UpdateServiceManagerClass();
IUpdateServiceManager updateServiceManager =
updateSession.CreateUpdateServiceManager();
IUpdateService updateService =
updateServiceManager.AddScanPackageService("Offlin e Sync Service",
"WSUSSCAN.cab", 0);
IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher();
updateSearcher.ServerSelection = ServerSelection.ssOthers
updateSearcher.ServiceID = updateService.ServiceID;
ISearchResult searchResult = updateSearcher.Search("Type='Software'");
....
Aug 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: wordsender | last post by:
Hey guys, I can't figure this one out, why is this simple script giving me problems? logfile=file(r'test.txt','w') logfile.write('datetime') test=logfile.readlines() When I run it I get...
6
by: SWE | last post by:
Hi all, I'm new to using style sheets for laying out my web pages. I have a horizontal navigation menu that is split into two sections - three buttons on the left and a submenu on the right that...
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
4
by: GVK | last post by:
Hi, I'm facing another problem with my network program. I'm writing a basic server that handles multiple clients. Whenever a client is connected, a new thread is created to handle it. The socket...
1
by: ERamirez | last post by:
I downloaded the Portal Starter Kit of http://asp.net and started adding a few modules. All debuggin localy worked fine but once I put it onto a Windos Server 2003 I keep getting the following...
9
by: Jim | last post by:
Hello, I'm trying to write exception-handling code that is OK in the presence of unicode error messages. I seem to have gotten all mixed up and I'd appreciate any un-mixing that anyone can...
2
by: jb | last post by:
Hi there, After installing and using MSAJAX 1.0 in one of my servers and websites, sometimes, I get the next error surfing the site: Bad Request (Invalid Verb) Somebody knows what does it...
5
by: Aussie Rules | last post by:
Hi, I am still having a problem using a datalist control using VB.net This is my code...... In the HTML page I have <asp:DataList ID="DataList1" runat="server">
0
by: Lexxzy | last post by:
Hi to all, I've a problem about to attach a recovered database file in the enterprise manager. My problem goes this way, I want to attach a recovered database file. So when I followed this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.