tags:

views:

638

answers:

3

Hello - I am creating a decoupled WMI provider in a class library. Everything I have read points towards including something along these lines:

[System.ComponentModel.RunInstaller(true)]
public class MyApplicationManagementInstaller : DefaultManagementInstaller { }

I gather the purpose of this installation is because the Windows WMI infrastructure needs to be aware of the structure of my WMI provider before it is used.

My question is - when is this "installer" ran? MSDN says that the installer will be invoked "during installation of an assembly", but I am not sure what that means or when it would happen in the context of a class library containing a WMI provider.

I was under the impression that this was an automated replacement for manually running InstallUtil.exe against the assembly containing the WMI provider, but changes I make to the provider are not recognised by the Windows WMI infrastructure unless I manually run InstallUtil from the command prompt. I can do this on my own machine during development, but if an application using the provider is deployed to other machines - what then?

It seems that this RunInstaller / DefaultManagementInstaller combination is not working properly - correct?

+1  A: 

As I understand, DefaultManagementInstaller is ran by installutil.exe - if you don't include it, the class is not installed in WMI. Maybe it is possible to create a 'setup project' or 'installer project' that runs it, but I'm not sure because I don't use Visual Studio.

[edit]

for remote instalation, an option could be to use Installutil with /MOF option to generate MOF for the assembly and use mofcomp to move it to WMI.

Uros Calakovic
+1  A: 

Thanks Uros. It does look like all that RunInstaller and DefaultManagementInstaller do is enable you to run InstallUtil successfully against the assembly. This is strange because I'm almost certain that I didn't know about InstallUtil at the point where I'd compiled and played with my first WMI provider.

I will look in to using the MOF file and for my own use I can just run the InstallUtil command line as a post build event in VS.

frou
+1  A: 

I use something like this to call InstallUtil programmatically:

    public static void Run( Type type )
    {
        // Register WMI stuff
        var installArgs = new[]
                                   {
                                       string.Format( "//logfile={0}", @"c:\Temp\sample.InstallLog" ), "//LogToConsole=false", "//ShowCallStack",
                                       type.Assembly.Location,
                                   };

        ManagedInstallerClass.InstallHelper( installArgs );
    }

Call this from your Main() method.

-dave

David Gardiner