WMI

From ISXKB

(Difference between revisions)
Jump to: navigation, search
m
Line 11: Line 11:
(This is based around IsGetObj.dll, which was originally written by someone else for use in InstallShield, but it works nicely in Inno as well.)
(This is based around IsGetObj.dll, which was originally written by someone else for use in InstallShield, but it works nicely in Inno as well.)
-
[[Media:Wmi.zip]]
+
[[Media:Wmi.zip|Download zip file]]
* wmi.isi: Inno script to include to provide functionality.  (This has only been tested in ANSI Inno; changes may be needed if you're using the Unicode version.)
* wmi.isi: Inno script to include to provide functionality.  (This has only been tested in ANSI Inno; changes may be needed if you're using the Unicode version.)

Revision as of 23:58, 8 September 2011

Contents

Windows Management Instrumentation

WMI provides a database-like interface to some of Windows' and applications' internals, which can be useful to interact with during installation, particularly for auto-detecting certain applications or configurations.

Basic Usage

WMI is accessed via COM; as such the CodeAutomation.iss example script and corresponding help topics should be your first point of call.

Helper Library

One thing that Inno is unfortunately not good at supporting at the moment is COM enumerators; a little outside assistance from a DLL is needed here.

(This is based around IsGetObj.dll, which was originally written by someone else for use in InstallShield, but it works nicely in Inno as well.)

Download zip file

  • wmi.isi: Inno script to include to provide functionality. (This has only been tested in ANSI Inno; changes may be needed if you're using the Unicode version.)
  • sqlserver.isi: Example usage script; see below.
  • IsGetObj.dll: DLL required by the installer.
  • GetObject.zip: source code for the DLL, for those interested (you don't need this to use it, unless you want to recompile for Unicode support).

Including wmi.isi provides the following functions:

   function ForEachStart(var ForEachObject: Variant; var ForEachEnum: Variant): Integer;
  • Creates an enumerator for the given object; returns an HRESULT status.
   function ForEachGetNextItem(var ForEachEnum: Variant; var ForEachItem: Variant): Integer;
  • Retrieves the next item from the given enumeration; returns an HRESULT status.
   function GetComObject(szFile: String; szProgId: String; var Obj: Variant): Integer;
  • Like GetActiveOleObject, but also supports creating objects by monikers.
   function WmiConnect(root: String): Variant;
  • Creates a connection to the specified WMI root.
   function ComEnumerate(obj: Variant): array of Variant;
  • Performs a complete enumeration on the given object, returning an array of the results.
   function WmiQuery(wmi: Variant; query: String): array of Variant;
  • Performs a WMI query, returning the results.

Usage Example

As an example of using these methods, the included sqlserver.isi script shows how to query for all installed SQL Server 2005/2008 instances on the machine (and is also written as a reusable component, for those interested in using that in itself).

And for an example of using that to determine if a particular SQL Server 2008 database instance is installed on the local machine...

   try
       servers := FindSqlServers('.');
       index := FindInstance(servers, 'MYAPP');
       foundDatabase := (index >= 0) and (servers[index].VersionMajor >= 10);
   except
       // an exception while trying to find the servers most likely means that none are installed...
       Log(GetExceptionMessage());
       foundDatabase := False;
   end;

Personal tools
Ads: