aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.Native/MsiInterop.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.Native/MsiInterop.cs')
-rw-r--r--src/WixToolset.Core.Native/MsiInterop.cs851
1 files changed, 851 insertions, 0 deletions
diff --git a/src/WixToolset.Core.Native/MsiInterop.cs b/src/WixToolset.Core.Native/MsiInterop.cs
new file mode 100644
index 00000000..8e5200c7
--- /dev/null
+++ b/src/WixToolset.Core.Native/MsiInterop.cs
@@ -0,0 +1,851 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Core.Native
4{
5 using System;
6 using System.Text;
7 using System.Runtime.InteropServices;
8 using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
9
10 /// <summary>
11 /// A callback function that the installer calls for progress notification and error messages.
12 /// </summary>
13 /// <param name="context">Pointer to an application context.
14 /// This parameter can be used for error checking.</param>
15 /// <param name="messageType">Specifies a combination of one message box style,
16 /// one message box icon type, one default button, and one installation message type.</param>
17 /// <param name="message">Specifies the message text.</param>
18 /// <returns>-1 for an error, 0 if no action was taken, 1 if OK, 3 to abort.</returns>
19 public delegate int InstallUIHandler(IntPtr context, uint messageType, [MarshalAs(UnmanagedType.LPWStr)] string message);
20
21 /// <summary>
22 /// Enum of predefined persist modes used when opening a database.
23 /// </summary>
24 public enum OpenDatabase
25 {
26 /// <summary>
27 /// Open a database read-only, no persistent changes.
28 /// </summary>
29 ReadOnly = MsiInterop.MSIDBOPENREADONLY,
30
31 /// <summary>
32 /// Open a database read/write in transaction mode.
33 /// </summary>
34 Transact = MsiInterop.MSIDBOPENTRANSACT,
35
36 /// <summary>
37 /// Open a database direct read/write without transaction.
38 /// </summary>
39 Direct = MsiInterop.MSIDBOPENDIRECT,
40
41 /// <summary>
42 /// Create a new database, transact mode read/write.
43 /// </summary>
44 Create = MsiInterop.MSIDBOPENCREATE,
45
46 /// <summary>
47 /// Create a new database, direct mode read/write.
48 /// </summary>
49 CreateDirect = MsiInterop.MSIDBOPENCREATEDIRECT,
50
51 /// <summary>
52 /// Indicates a patch file is being opened.
53 /// </summary>
54 OpenPatchFile = MsiInterop.MSIDBOPENPATCHFILE
55 }
56
57 /// <summary>
58 /// The errors to suppress when applying a transform.
59 /// </summary>
60 [Flags]
61 public enum TransformErrorConditions
62 {
63 /// <summary>
64 /// None of the following conditions.
65 /// </summary>
66 None = 0x0,
67
68 /// <summary>
69 /// Suppress error when adding a row that exists.
70 /// </summary>
71 AddExistingRow = 0x1,
72
73 /// <summary>
74 /// Suppress error when deleting a row that does not exist.
75 /// </summary>
76 DeleteMissingRow = 0x2,
77
78 /// <summary>
79 /// Suppress error when adding a table that exists.
80 /// </summary>
81 AddExistingTable = 0x4,
82
83 /// <summary>
84 /// Suppress error when deleting a table that does not exist.
85 /// </summary>
86 DeleteMissingTable = 0x8,
87
88 /// <summary>
89 /// Suppress error when updating a row that does not exist.
90 /// </summary>
91 UpdateMissingRow = 0x10,
92
93 /// <summary>
94 /// Suppress error when transform and database code pages do not match, and their code pages are neutral.
95 /// </summary>
96 ChangeCodepage = 0x20,
97
98 /// <summary>
99 /// Create the temporary _TransformView table when applying a transform.
100 /// </summary>
101 ViewTransform = 0x100,
102
103 /// <summary>
104 /// Suppress all errors but the option to create the temporary _TransformView table.
105 /// </summary>
106 All = 0x3F
107 }
108
109 /// <summary>
110 /// The validation to run while applying a transform.
111 /// </summary>
112 [Flags]
113 public enum TransformValidations
114 {
115 /// <summary>
116 /// Do not validate properties.
117 /// </summary>
118 None = 0x0,
119
120 /// <summary>
121 /// Default language must match base database.
122 /// </summary>
123 Language = 0x1,
124
125 /// <summary>
126 /// Product must match base database.
127 /// </summary>
128 Product = 0x2,
129
130 /// <summary>
131 /// Check major version only.
132 /// </summary>
133 MajorVersion = 0x8,
134
135 /// <summary>
136 /// Check major and minor versions only.
137 /// </summary>
138 MinorVersion = 0x10,
139
140 /// <summary>
141 /// Check major, minor, and update versions.
142 /// </summary>
143 UpdateVersion = 0x20,
144
145 /// <summary>
146 /// Installed version &lt; base version.
147 /// </summary>
148 NewLessBaseVersion = 0x40,
149
150 /// <summary>
151 /// Installed version &lt;= base version.
152 /// </summary>
153 NewLessEqualBaseVersion = 0x80,
154
155 /// <summary>
156 /// Installed version = base version.
157 /// </summary>
158 NewEqualBaseVersion = 0x100,
159
160 /// <summary>
161 /// Installed version &gt;= base version.
162 /// </summary>
163 NewGreaterEqualBaseVersion = 0x200,
164
165 /// <summary>
166 /// Installed version &gt; base version.
167 /// </summary>
168 NewGreaterBaseVersion = 0x400,
169
170 /// <summary>
171 /// UpgradeCode must match base database.
172 /// </summary>
173 UpgradeCode = 0x800
174 }
175
176 /// <summary>
177 /// Class exposing static functions and structs from MSI API.
178 /// </summary>
179 public sealed class MsiInterop
180 {
181 // Patching constants
182 public const int MsiMaxStreamNameLength = 62; // http://msdn2.microsoft.com/library/aa370551.aspx
183
184 // Component.Attributes
185 public const int MsidbComponentAttributesLocalOnly = 0;
186 public const int MsidbComponentAttributesSourceOnly = 1;
187 public const int MsidbComponentAttributesOptional = 2;
188 public const int MsidbComponentAttributesRegistryKeyPath = 4;
189 public const int MsidbComponentAttributesSharedDllRefCount = 8;
190 public const int MsidbComponentAttributesPermanent = 16;
191 public const int MsidbComponentAttributesODBCDataSource = 32;
192 public const int MsidbComponentAttributesTransitive = 64;
193 public const int MsidbComponentAttributesNeverOverwrite = 128;
194 public const int MsidbComponentAttributes64bit = 256;
195 public const int MsidbComponentAttributesDisableRegistryReflection = 512;
196 public const int MsidbComponentAttributesUninstallOnSupersedence = 1024;
197 public const int MsidbComponentAttributesShared = 2048;
198
199 // BBControl.Attributes & Control.Attributes
200 public const int MsidbControlAttributesVisible = 0x00000001;
201 public const int MsidbControlAttributesEnabled = 0x00000002;
202 public const int MsidbControlAttributesSunken = 0x00000004;
203 public const int MsidbControlAttributesIndirect = 0x00000008;
204 public const int MsidbControlAttributesInteger = 0x00000010;
205 public const int MsidbControlAttributesRTLRO = 0x00000020;
206 public const int MsidbControlAttributesRightAligned = 0x00000040;
207 public const int MsidbControlAttributesLeftScroll = 0x00000080;
208 public const int MsidbControlAttributesBiDi = MsidbControlAttributesRTLRO | MsidbControlAttributesRightAligned | MsidbControlAttributesLeftScroll;
209
210 // Text controls
211 public const int MsidbControlAttributesTransparent = 0x00010000;
212 public const int MsidbControlAttributesNoPrefix = 0x00020000;
213 public const int MsidbControlAttributesNoWrap = 0x00040000;
214 public const int MsidbControlAttributesFormatSize = 0x00080000;
215 public const int MsidbControlAttributesUsersLanguage = 0x00100000;
216
217 // Edit controls
218 public const int MsidbControlAttributesMultiline = 0x00010000;
219 public const int MsidbControlAttributesPasswordInput = 0x00200000;
220
221 // ProgressBar controls
222 public const int MsidbControlAttributesProgress95 = 0x00010000;
223
224 // VolumeSelectCombo and DirectoryCombo controls
225 public const int MsidbControlAttributesRemovableVolume = 0x00010000;
226 public const int MsidbControlAttributesFixedVolume = 0x00020000;
227 public const int MsidbControlAttributesRemoteVolume = 0x00040000;
228 public const int MsidbControlAttributesCDROMVolume = 0x00080000;
229 public const int MsidbControlAttributesRAMDiskVolume = 0x00100000;
230 public const int MsidbControlAttributesFloppyVolume = 0x00200000;
231
232 // VolumeCostList controls
233 public const int MsidbControlShowRollbackCost = 0x00400000;
234
235 // ListBox and ComboBox controls
236 public const int MsidbControlAttributesSorted = 0x00010000;
237 public const int MsidbControlAttributesComboList = 0x00020000;
238
239 // picture button controls
240 public const int MsidbControlAttributesImageHandle = 0x00010000;
241 public const int MsidbControlAttributesPushLike = 0x00020000;
242 public const int MsidbControlAttributesBitmap = 0x00040000;
243 public const int MsidbControlAttributesIcon = 0x00080000;
244 public const int MsidbControlAttributesFixedSize = 0x00100000;
245 public const int MsidbControlAttributesIconSize16 = 0x00200000;
246 public const int MsidbControlAttributesIconSize32 = 0x00400000;
247 public const int MsidbControlAttributesIconSize48 = 0x00600000;
248 public const int MsidbControlAttributesElevationShield = 0x00800000;
249
250 // RadioButton controls
251 public const int MsidbControlAttributesHasBorder = 0x01000000;
252
253 // CustomAction.Type
254 // executable types
255 public const int MsidbCustomActionTypeDll = 0x00000001; // Target = entry point name
256 public const int MsidbCustomActionTypeExe = 0x00000002; // Target = command line args
257 public const int MsidbCustomActionTypeTextData = 0x00000003; // Target = text string to be formatted and set into property
258 public const int MsidbCustomActionTypeJScript = 0x00000005; // Target = entry point name; null if none to call
259 public const int MsidbCustomActionTypeVBScript = 0x00000006; // Target = entry point name; null if none to call
260 public const int MsidbCustomActionTypeInstall = 0x00000007; // Target = property list for nested engine initialization
261 public const int MsidbCustomActionTypeSourceBits = 0x00000030;
262 public const int MsidbCustomActionTypeTargetBits = 0x00000007;
263 public const int MsidbCustomActionTypeReturnBits = 0x000000C0;
264 public const int MsidbCustomActionTypeExecuteBits = 0x00000700;
265
266 // source of code
267 public const int MsidbCustomActionTypeBinaryData = 0x00000000; // Source = Binary.Name; data stored in stream
268 public const int MsidbCustomActionTypeSourceFile = 0x00000010; // Source = File.File; file part of installation
269 public const int MsidbCustomActionTypeDirectory = 0x00000020; // Source = Directory.Directory; folder containing existing file
270 public const int MsidbCustomActionTypeProperty = 0x00000030; // Source = Property.Property; full path to executable
271
272 // return processing; default is syncronous execution; process return code
273 public const int MsidbCustomActionTypeContinue = 0x00000040; // ignore action return status; continue running
274 public const int MsidbCustomActionTypeAsync = 0x00000080; // run asynchronously
275
276 // execution scheduling flags; default is execute whenever sequenced
277 public const int MsidbCustomActionTypeFirstSequence = 0x00000100; // skip if UI sequence already run
278 public const int MsidbCustomActionTypeOncePerProcess = 0x00000200; // skip if UI sequence already run in same process
279 public const int MsidbCustomActionTypeClientRepeat = 0x00000300; // run on client only if UI already run on client
280 public const int MsidbCustomActionTypeInScript = 0x00000400; // queue for execution within script
281 public const int MsidbCustomActionTypeRollback = 0x00000100; // in conjunction with InScript: queue in Rollback script
282 public const int MsidbCustomActionTypeCommit = 0x00000200; // in conjunction with InScript: run Commit ops from script on success
283
284 // security context flag; default to impersonate as user; valid only if InScript
285 public const int MsidbCustomActionTypeNoImpersonate = 0x00000800; // no impersonation; run in system context
286 public const int MsidbCustomActionTypeTSAware = 0x00004000; // impersonate for per-machine installs on TS machines
287 public const int MsidbCustomActionType64BitScript = 0x00001000; // script should run in 64bit process
288 public const int MsidbCustomActionTypeHideTarget = 0x00002000; // don't record the contents of the Target field in the log file.
289
290 public const int MsidbCustomActionTypePatchUninstall = 0x00008000; // run on patch uninstall
291
292 // Dialog.Attributes
293 public const int MsidbDialogAttributesVisible = 0x00000001;
294 public const int MsidbDialogAttributesModal = 0x00000002;
295 public const int MsidbDialogAttributesMinimize = 0x00000004;
296 public const int MsidbDialogAttributesSysModal = 0x00000008;
297 public const int MsidbDialogAttributesKeepModeless = 0x00000010;
298 public const int MsidbDialogAttributesTrackDiskSpace = 0x00000020;
299 public const int MsidbDialogAttributesUseCustomPalette = 0x00000040;
300 public const int MsidbDialogAttributesRTLRO = 0x00000080;
301 public const int MsidbDialogAttributesRightAligned = 0x00000100;
302 public const int MsidbDialogAttributesLeftScroll = 0x00000200;
303 public const int MsidbDialogAttributesBiDi = MsidbDialogAttributesRTLRO | MsidbDialogAttributesRightAligned | MsidbDialogAttributesLeftScroll;
304 public const int MsidbDialogAttributesError = 0x00010000;
305 public const int CommonControlAttributesInvert = MsidbControlAttributesVisible + MsidbControlAttributesEnabled;
306 public const int DialogAttributesInvert = MsidbDialogAttributesVisible + MsidbDialogAttributesModal + MsidbDialogAttributesMinimize;
307
308 // Feature.Attributes
309 public const int MsidbFeatureAttributesFavorLocal = 0;
310 public const int MsidbFeatureAttributesFavorSource = 1;
311 public const int MsidbFeatureAttributesFollowParent = 2;
312 public const int MsidbFeatureAttributesFavorAdvertise = 4;
313 public const int MsidbFeatureAttributesDisallowAdvertise = 8;
314 public const int MsidbFeatureAttributesUIDisallowAbsent = 16;
315 public const int MsidbFeatureAttributesNoUnsupportedAdvertise = 32;
316
317 // File.Attributes
318 public const int MsidbFileAttributesReadOnly = 1;
319 public const int MsidbFileAttributesHidden = 2;
320 public const int MsidbFileAttributesSystem = 4;
321 public const int MsidbFileAttributesVital = 512;
322 public const int MsidbFileAttributesChecksum = 1024;
323 public const int MsidbFileAttributesPatchAdded = 4096;
324 public const int MsidbFileAttributesNoncompressed = 8192;
325 public const int MsidbFileAttributesCompressed = 16384;
326
327 // IniFile.Action & RemoveIniFile.Action
328 public const int MsidbIniFileActionAddLine = 0;
329 public const int MsidbIniFileActionCreateLine = 1;
330 public const int MsidbIniFileActionRemoveLine = 2;
331 public const int MsidbIniFileActionAddTag = 3;
332 public const int MsidbIniFileActionRemoveTag = 4;
333
334 // MoveFile.Options
335 public const int MsidbMoveFileOptionsMove = 1;
336
337 // ServiceInstall.Attributes
338 public const int MsidbServiceInstallOwnProcess = 0x00000010;
339 public const int MsidbServiceInstallShareProcess = 0x00000020;
340 public const int MsidbServiceInstallInteractive = 0x00000100;
341 public const int MsidbServiceInstallAutoStart = 0x00000002;
342 public const int MsidbServiceInstallDemandStart = 0x00000003;
343 public const int MsidbServiceInstallDisabled = 0x00000004;
344 public const int MsidbServiceInstallErrorIgnore = 0x00000000;
345 public const int MsidbServiceInstallErrorNormal = 0x00000001;
346 public const int MsidbServiceInstallErrorCritical = 0x00000003;
347 public const int MsidbServiceInstallErrorControlVital = 0x00008000;
348
349 // ServiceConfig.Event
350 public const int MsidbServiceConfigEventInstall = 0x00000001;
351 public const int MsidbServiceConfigEventUninstall = 0x00000002;
352 public const int MsidbServiceConfigEventReinstall = 0x00000004;
353
354 // ServiceControl.Attributes
355 public const int MsidbServiceControlEventStart = 0x00000001;
356 public const int MsidbServiceControlEventStop = 0x00000002;
357 public const int MsidbServiceControlEventDelete = 0x00000008;
358 public const int MsidbServiceControlEventUninstallStart = 0x00000010;
359 public const int MsidbServiceControlEventUninstallStop = 0x00000020;
360 public const int MsidbServiceControlEventUninstallDelete = 0x00000080;
361
362 // TextStyle.StyleBits
363 public const int MsidbTextStyleStyleBitsBold = 1;
364 public const int MsidbTextStyleStyleBitsItalic = 2;
365 public const int MsidbTextStyleStyleBitsUnderline = 4;
366 public const int MsidbTextStyleStyleBitsStrike = 8;
367
368 // Upgrade.Attributes
369 public const int MsidbUpgradeAttributesMigrateFeatures = 0x00000001;
370 public const int MsidbUpgradeAttributesOnlyDetect = 0x00000002;
371 public const int MsidbUpgradeAttributesIgnoreRemoveFailure = 0x00000004;
372 public const int MsidbUpgradeAttributesVersionMinInclusive = 0x00000100;
373 public const int MsidbUpgradeAttributesVersionMaxInclusive = 0x00000200;
374 public const int MsidbUpgradeAttributesLanguagesExclusive = 0x00000400;
375
376 // Registry Hive Roots
377 public const int MsidbRegistryRootClassesRoot = 0;
378 public const int MsidbRegistryRootCurrentUser = 1;
379 public const int MsidbRegistryRootLocalMachine = 2;
380 public const int MsidbRegistryRootUsers = 3;
381
382 // Locator Types
383 public const int MsidbLocatorTypeDirectory = 0;
384 public const int MsidbLocatorTypeFileName = 1;
385 public const int MsidbLocatorTypeRawValue = 2;
386 public const int MsidbLocatorType64bit = 16;
387
388 public const int MsidbClassAttributesRelativePath = 1;
389
390 // RemoveFile.InstallMode
391 public const int MsidbRemoveFileInstallModeOnInstall = 0x00000001;
392 public const int MsidbRemoveFileInstallModeOnRemove = 0x00000002;
393 public const int MsidbRemoveFileInstallModeOnBoth = 0x00000003;
394
395 // ODBCDataSource.Registration
396 public const int MsidbODBCDataSourceRegistrationPerMachine = 0;
397 public const int MsidbODBCDataSourceRegistrationPerUser = 1;
398
399 // ModuleConfiguration.Format
400 public const int MsidbModuleConfigurationFormatText = 0;
401 public const int MsidbModuleConfigurationFormatKey = 1;
402 public const int MsidbModuleConfigurationFormatInteger = 2;
403 public const int MsidbModuleConfigurationFormatBitfield = 3;
404
405 // ModuleConfiguration.Attributes
406 public const int MsidbMsmConfigurableOptionKeyNoOrphan = 1;
407 public const int MsidbMsmConfigurableOptionNonNullable = 2;
408
409 // ' Windows API function ShowWindow constants - used in Shortcut table
410 public const int SWSHOWNORMAL = 0x00000001;
411 public const int SWSHOWMAXIMIZED = 0x00000003;
412 public const int SWSHOWMINNOACTIVE = 0x00000007;
413
414 // NameToBit arrays
415 // UI elements
416 public static readonly string[] CommonControlAttributes = { "Hidden", "Disabled", "Sunken", "Indirect", "Integer", "RightToLeft", "RightAligned", "LeftScroll" };
417 public static readonly string[] TextControlAttributes = { "Transparent", "NoPrefix", "NoWrap", "FormatSize", "UserLanguage" };
418 public static readonly string[] HyperlinkControlAttributes = { "Transparent" };
419 public static readonly string[] EditControlAttributes = { "Multiline", null, null, null, null, "Password" };
420 public static readonly string[] ProgressControlAttributes = { "ProgressBlocks" };
421 public static readonly string[] VolumeControlAttributes = { "Removable", "Fixed", "Remote", "CDROM", "RAMDisk", "Floppy", "ShowRollbackCost" };
422 public static readonly string[] ListboxControlAttributes = { "Sorted", null, null, null, "UserLanguage" };
423 public static readonly string[] ListviewControlAttributes = { "Sorted", null, null, null, "FixedSize", "Icon16", "Icon32" };
424 public static readonly string[] ComboboxControlAttributes = { "Sorted", "ComboList", null, null, "UserLanguage" };
425 public static readonly string[] RadioControlAttributes = { "Image", "PushLike", "Bitmap", "Icon", "FixedSize", "Icon16", "Icon32", null, "HasBorder" };
426 public static readonly string[] ButtonControlAttributes = { "Image", null, "Bitmap", "Icon", "FixedSize", "Icon16", "Icon32", "ElevationShield" };
427 public static readonly string[] IconControlAttributes = { "Image", null, null, null, "FixedSize", "Icon16", "Icon32" };
428 public static readonly string[] BitmapControlAttributes = { "Image", null, null, null, "FixedSize" };
429 public static readonly string[] CheckboxControlAttributes = { null, "PushLike", "Bitmap", "Icon", "FixedSize", "Icon16", "Icon32" };
430
431 public const int MsidbEmbeddedUI = 0x01;
432 public const int MsidbEmbeddedHandlesBasic = 0x02;
433
434 public const int INSTALLLOGMODE_FATALEXIT = 0x00001;
435 public const int INSTALLLOGMODE_ERROR = 0x00002;
436 public const int INSTALLLOGMODE_WARNING = 0x00004;
437 public const int INSTALLLOGMODE_USER = 0x00008;
438 public const int INSTALLLOGMODE_INFO = 0x00010;
439 public const int INSTALLLOGMODE_FILESINUSE = 0x00020;
440 public const int INSTALLLOGMODE_RESOLVESOURCE = 0x00040;
441 public const int INSTALLLOGMODE_OUTOFDISKSPACE = 0x00080;
442 public const int INSTALLLOGMODE_ACTIONSTART = 0x00100;
443 public const int INSTALLLOGMODE_ACTIONDATA = 0x00200;
444 public const int INSTALLLOGMODE_PROGRESS = 0x00400;
445 public const int INSTALLLOGMODE_COMMONDATA = 0x00800;
446 public const int INSTALLLOGMODE_INITIALIZE = 0x01000;
447 public const int INSTALLLOGMODE_TERMINATE = 0x02000;
448 public const int INSTALLLOGMODE_SHOWDIALOG = 0x04000;
449 public const int INSTALLLOGMODE_RMFILESINUSE = 0x02000000;
450 public const int INSTALLLOGMODE_INSTALLSTART = 0x04000000;
451 public const int INSTALLLOGMODE_INSTALLEND = 0x08000000;
452
453 public const int MSICONDITIONFALSE = 0; // The table is temporary.
454 public const int MSICONDITIONTRUE = 1; // The table is persistent.
455 public const int MSICONDITIONNONE = 2; // The table is unknown.
456 public const int MSICONDITIONERROR = 3; // An invalid handle or invalid parameter was passed to the function.
457
458 public const int MSIDBOPENREADONLY = 0;
459 public const int MSIDBOPENTRANSACT = 1;
460 public const int MSIDBOPENDIRECT = 2;
461 public const int MSIDBOPENCREATE = 3;
462 public const int MSIDBOPENCREATEDIRECT = 4;
463 public const int MSIDBOPENPATCHFILE = 32;
464
465 public const int MSIMODIFYSEEK = -1; // Refreshes the information in the supplied record without changing the position in the result set and without affecting subsequent fetch operations. The record may then be used for subsequent Update, Delete, and Refresh. All primary key columns of the table must be in the query and the record must have at least as many fields as the query. Seek cannot be used with multi-table queries. This mode cannot be used with a view containing joins. See also the remarks.
466 public const int MSIMODIFYREFRESH = 0; // Refreshes the information in the record. Must first call MsiViewFetch with the same record. Fails for a deleted row. Works with read-write and read-only records.
467 public const int MSIMODIFYINSERT = 1; // Inserts a record. Fails if a row with the same primary keys exists. Fails with a read-only database. This mode cannot be used with a view containing joins.
468 public const int MSIMODIFYUPDATE = 2; // Updates an existing record. Nonprimary keys only. Must first call MsiViewFetch. Fails with a deleted record. Works only with read-write records.
469 public const int MSIMODIFYASSIGN = 3; // Writes current data in the cursor to a table row. Updates record if the primary keys match an existing row and inserts if they do not match. Fails with a read-only database. This mode cannot be used with a view containing joins.
470 public const int MSIMODIFYREPLACE = 4; // Updates or deletes and inserts a record into a table. Must first call MsiViewFetch with the same record. Updates record if the primary keys are unchanged. Deletes old row and inserts new if primary keys have changed. Fails with a read-only database. This mode cannot be used with a view containing joins.
471 public const int MSIMODIFYMERGE = 5; // Inserts or validates a record in a table. Inserts if primary keys do not match any row and validates if there is a match. Fails if the record does not match the data in the table. Fails if there is a record with a duplicate key that is not identical. Works only with read-write records. This mode cannot be used with a view containing joins.
472 public const int MSIMODIFYDELETE = 6; // Remove a row from the table. You must first call the MsiViewFetch function with the same record. Fails if the row has been deleted. Works only with read-write records. This mode cannot be used with a view containing joins.
473 public const int MSIMODIFYINSERTTEMPORARY = 7; // Inserts a temporary record. The information is not persistent. Fails if a row with the same primary key exists. Works only with read-write records. This mode cannot be used with a view containing joins.
474 public const int MSIMODIFYVALIDATE = 8; // Validates a record. Does not validate across joins. You must first call the MsiViewFetch function with the same record. Obtain validation errors with MsiViewGetError. Works with read-write and read-only records. This mode cannot be used with a view containing joins.
475 public const int MSIMODIFYVALIDATENEW = 9; // Validate a new record. Does not validate across joins. Checks for duplicate keys. Obtain validation errors by calling MsiViewGetError. Works with read-write and read-only records. This mode cannot be used with a view containing joins.
476 public const int MSIMODIFYVALIDATEFIELD = 10; // Validates fields of a fetched or new record. Can validate one or more fields of an incomplete record. Obtain validation errors by calling MsiViewGetError. Works with read-write and read-only records. This mode cannot be used with a view containing joins.
477 public const int MSIMODIFYVALIDATEDELETE = 11; // Validates a record that will be deleted later. You must first call MsiViewFetch. Fails if another row refers to the primary keys of this row. Validation does not check for the existence of the primary keys of this row in properties or strings. Does not check if a column is a foreign key to multiple tables. Obtain validation errors by calling MsiViewGetError. Works with read-write and read-only records. This mode cannot be used with a view containing joins.
478
479 public const uint VTI2 = 2;
480 public const uint VTI4 = 3;
481 public const uint VTLPWSTR = 30;
482 public const uint VTFILETIME = 64;
483
484 public const int MSICOLINFONAMES = 0; // return column names
485 public const int MSICOLINFOTYPES = 1; // return column definitions, datatype code followed by width
486
487 /// <summary>
488 /// Protect the constructor.
489 /// </summary>
490 private MsiInterop()
491 {
492 }
493
494 /// <summary>
495 /// PInvoke of MsiCloseHandle.
496 /// </summary>
497 /// <param name="database">Handle to a database.</param>
498 /// <returns>Error code.</returns>
499 [DllImport("msi.dll", EntryPoint = "MsiCloseHandle", CharSet = CharSet.Unicode, ExactSpelling = true)]
500 public static extern int MsiCloseHandle(uint database);
501
502 /// <summary>
503 /// PInvoke of MsiCreateRecord
504 /// </summary>
505 /// <param name="parameters">Count of columns in the record.</param>
506 /// <returns>Handle referencing the record.</returns>
507 [DllImport("msi.dll", EntryPoint = "MsiCreateRecord", CharSet = CharSet.Unicode, ExactSpelling = true)]
508 public static extern uint MsiCreateRecord(int parameters);
509
510 /// <summary>
511 /// Creates summary information of an existing transform to include validation and error conditions.
512 /// </summary>
513 /// <param name="database">The handle to the database that contains the new database summary information.</param>
514 /// <param name="referenceDatabase">The handle to the database that contains the original summary information.</param>
515 /// <param name="transformFile">The name of the transform to which the summary information is added.</param>
516 /// <param name="errorConditions">The error conditions that should be suppressed when the transform is applied.</param>
517 /// <param name="validations">Specifies the properties to be validated to verify that the transform can be applied to the database.</param>
518 /// <returns>Error code.</returns>
519 [DllImport("msi.dll", EntryPoint = "MsiCreateTransformSummaryInfoW", CharSet = CharSet.Unicode, ExactSpelling = true)]
520 public static extern int MsiCreateTransformSummaryInfo(uint database, uint referenceDatabase, string transformFile, TransformErrorConditions errorConditions, TransformValidations validations);
521
522 /// <summary>
523 /// Applies a transform to a database.
524 /// </summary>
525 /// <param name="database">Handle to the database obtained from MsiOpenDatabase to transform.</param>
526 /// <param name="transformFile">Specifies the name of the transform file to apply.</param>
527 /// <param name="errorConditions">Error conditions that should be suppressed.</param>
528 /// <returns>Error code.</returns>
529 [DllImport("msi.dll", EntryPoint = "MsiDatabaseApplyTransformW", CharSet = CharSet.Unicode, ExactSpelling = true)]
530 public static extern int MsiDatabaseApplyTransform(uint database, string transformFile, TransformErrorConditions errorConditions);
531
532 /// <summary>
533 /// PInvoke of MsiDatabaseCommit.
534 /// </summary>
535 /// <param name="database">Handle to a databse.</param>
536 /// <returns>Error code.</returns>
537 [DllImport("msi.dll", EntryPoint = "MsiDatabaseCommit", CharSet = CharSet.Unicode, ExactSpelling = true)]
538 public static extern int MsiDatabaseCommit(uint database);
539
540 /// <summary>
541 /// PInvoke of MsiDatabaseExportW.
542 /// </summary>
543 /// <param name="database">Handle to a database.</param>
544 /// <param name="tableName">Table name.</param>
545 /// <param name="folderPath">Folder path.</param>
546 /// <param name="fileName">File name.</param>
547 /// <returns>Error code.</returns>
548 [DllImport("msi.dll", EntryPoint = "MsiDatabaseExportW", CharSet = CharSet.Unicode, ExactSpelling = true)]
549 public static extern int MsiDatabaseExport(uint database, string tableName, string folderPath, string fileName);
550
551 /// <summary>
552 /// Generates a transform file of differences between two databases.
553 /// </summary>
554 /// <param name="database">Handle to the database obtained from MsiOpenDatabase that includes the changes.</param>
555 /// <param name="databaseReference">Handle to the database obtained from MsiOpenDatabase that does not include the changes.</param>
556 /// <param name="transformFile">A null-terminated string that specifies the name of the transform file being generated.
557 /// This parameter can be null. If szTransformFile is null, you can use MsiDatabaseGenerateTransform to test whether two
558 /// databases are identical without creating a transform. If the databases are identical, the function returns ERROR_NO_DATA.
559 /// If the databases are different the function returns NOERROR.</param>
560 /// <param name="reserved1">This is a reserved argument and must be set to 0.</param>
561 /// <param name="reserved2">This is a reserved argument and must be set to 0.</param>
562 /// <returns>Error code.</returns>
563 [DllImport("msi.dll", EntryPoint = "MsiDatabaseGenerateTransformW", CharSet = CharSet.Unicode, ExactSpelling = true)]
564 public static extern int MsiDatabaseGenerateTransform(uint database, uint databaseReference, string transformFile, int reserved1, int reserved2);
565
566 /// <summary>
567 /// PInvoke of MsiDatabaseImportW.
568 /// </summary>
569 /// <param name="database">Handle to a database.</param>
570 /// <param name="folderPath">Folder path.</param>
571 /// <param name="fileName">File name.</param>
572 /// <returns>Error code.</returns>
573 [DllImport("msi.dll", EntryPoint = "MsiDatabaseImportW", CharSet = CharSet.Unicode, ExactSpelling = true)]
574 public static extern int MsiDatabaseImport(uint database, string folderPath, string fileName);
575
576 /// <summary>
577 /// PInvoke of MsiDatabaseMergeW.
578 /// </summary>
579 /// <param name="database">The handle to the database obtained from MsiOpenDatabase.</param>
580 /// <param name="databaseMerge">The handle to the database obtained from MsiOpenDatabase to merge into the base database.</param>
581 /// <param name="tableName">The name of the table to receive merge conflict information.</param>
582 /// <returns>Error code.</returns>
583 [DllImport("msi.dll", EntryPoint = "MsiDatabaseMergeW", CharSet = CharSet.Unicode, ExactSpelling = true)]
584 public static extern int MsiDatabaseMerge(uint database, uint databaseMerge, string tableName);
585
586 /// <summary>
587 /// PInvoke of MsiDatabaseOpenViewW.
588 /// </summary>
589 /// <param name="database">Handle to a database.</param>
590 /// <param name="query">SQL query.</param>
591 /// <param name="view">View handle.</param>
592 /// <returns>Error code.</returns>
593 [DllImport("msi.dll", EntryPoint = "MsiDatabaseOpenViewW", CharSet = CharSet.Unicode, ExactSpelling = true)]
594 public static extern int MsiDatabaseOpenView(uint database, string query, out uint view);
595
596 /// <summary>
597 /// PInvoke of MsiGetFileHashW.
598 /// </summary>
599 /// <param name="filePath">File path.</param>
600 /// <param name="options">Hash options (must be 0).</param>
601 /// <param name="hash">Buffer to recieve hash.</param>
602 /// <returns>Error code.</returns>
603 [DllImport("msi.dll", EntryPoint = "MsiGetFileHashW", CharSet = CharSet.Unicode, ExactSpelling = true)]
604 public static extern int MsiGetFileHash(string filePath, uint options, MSIFILEHASHINFO hash);
605
606 /// <summary>
607 /// PInvoke of MsiGetFileVersionW.
608 /// </summary>
609 /// <param name="filePath">File path.</param>
610 /// <param name="versionBuf">Buffer to receive version info.</param>
611 /// <param name="versionBufSize">Size of version buffer.</param>
612 /// <param name="langBuf">Buffer to recieve lang info.</param>
613 /// <param name="langBufSize">Size of lang buffer.</param>
614 /// <returns>Error code.</returns>
615 [DllImport("msi.dll", EntryPoint = "MsiGetFileVersionW", CharSet = CharSet.Unicode, ExactSpelling = true)]
616 public static extern int MsiGetFileVersion(string filePath, StringBuilder versionBuf, ref int versionBufSize, StringBuilder langBuf, ref int langBufSize);
617
618 /// <summary>
619 /// PInvoke of MsiGetLastErrorRecord.
620 /// </summary>
621 /// <returns>Handle to error record if one exists.</returns>
622 [DllImport("msi.dll", EntryPoint = "MsiGetLastErrorRecord", CharSet = CharSet.Unicode, ExactSpelling = true)]
623 public static extern uint MsiGetLastErrorRecord();
624
625 /// <summary>
626 /// PInvoke of MsiDatabaseGetPrimaryKeysW.
627 /// </summary>
628 /// <param name="database">Handle to a database.</param>
629 /// <param name="tableName">Table name.</param>
630 /// <param name="record">Handle to receive resulting record.</param>
631 /// <returns>Error code.</returns>
632 [DllImport("msi.dll", EntryPoint = "MsiDatabaseGetPrimaryKeysW", CharSet = CharSet.Unicode, ExactSpelling = true)]
633 public static extern int MsiDatabaseGetPrimaryKeys(uint database, string tableName, out uint record);
634
635 /// <summary>
636 /// PInvoke of MsiDoActionW.
637 /// </summary>
638 /// <param name="product">Handle to the installation provided to a DLL custom action or
639 /// obtained through MsiOpenPackage, MsiOpenPackageEx, or MsiOpenProduct.</param>
640 /// <param name="action">Specifies the action to execute.</param>
641 /// <returns>Error code.</returns>
642 [DllImport("msi.dll", EntryPoint = "MsiDoActionW", CharSet = CharSet.Unicode, ExactSpelling = true)]
643 public static extern int MsiDoAction(uint product, string action);
644
645 /// <summary>
646 /// PInvoke of MsiGetSummaryInformationW. Can use either database handle or database path as input.
647 /// </summary>
648 /// <param name="database">Handle to a database.</param>
649 /// <param name="databasePath">Path to a database.</param>
650 /// <param name="updateCount">Max number of updated values.</param>
651 /// <param name="summaryInfo">Handle to summary information.</param>
652 /// <returns>Error code.</returns>
653 [DllImport("msi.dll", EntryPoint = "MsiGetSummaryInformationW", CharSet = CharSet.Unicode, ExactSpelling = true)]
654 public static extern int MsiGetSummaryInformation(uint database, string databasePath, uint updateCount, ref uint summaryInfo);
655
656 /// <summary>
657 /// PInvoke of MsiDatabaseIsTablePersitentW.
658 /// </summary>
659 /// <param name="database">Handle to a database.</param>
660 /// <param name="tableName">Table name.</param>
661 /// <returns>MSICONDITION</returns>
662 [DllImport("msi.dll", EntryPoint = "MsiDatabaseIsTablePersistentW", CharSet = CharSet.Unicode, ExactSpelling = true)]
663 public static extern int MsiDatabaseIsTablePersistent(uint database, string tableName);
664
665 /// <summary>
666 /// PInvoke of MsiOpenDatabaseW.
667 /// </summary>
668 /// <param name="databasePath">Path to database.</param>
669 /// <param name="persist">Persist mode.</param>
670 /// <param name="database">Handle to database.</param>
671 /// <returns>Error code.</returns>
672 [DllImport("msi.dll", EntryPoint = "MsiOpenDatabaseW", CharSet = CharSet.Unicode, ExactSpelling = true)]
673 public static extern int MsiOpenDatabase(string databasePath, IntPtr persist, out uint database);
674
675 /// <summary>
676 /// PInvoke of MsiOpenPackageW.
677 /// </summary>
678 /// <param name="packagePath">The path to the package.</param>
679 /// <param name="product">A pointer to a variable that receives the product handle.</param>
680 /// <returns>Error code.</returns>
681 [DllImport("msi.dll", EntryPoint = "MsiOpenPackageW", CharSet = CharSet.Unicode, ExactSpelling = true)]
682 public static extern int MsiOpenPackage(string packagePath, out uint product);
683
684 /// <summary>
685 /// PInvoke of MsiRecordIsNull.
686 /// </summary>
687 /// <param name="record">MSI Record handle.</param>
688 /// <param name="field">Index of field to check for null value.</param>
689 /// <returns>true if the field is null, false if not, and an error code for any error.</returns>
690 [DllImport("msi.dll", EntryPoint = "MsiRecordIsNull", CharSet = CharSet.Unicode, ExactSpelling = true)]
691 public static extern int MsiRecordIsNull(uint record, int field);
692
693 /// <summary>
694 /// PInvoke of MsiRecordGetInteger.
695 /// </summary>
696 /// <param name="record">MSI Record handle.</param>
697 /// <param name="field">Index of field to retrieve integer from.</param>
698 /// <returns>Integer value.</returns>
699 [DllImport("msi.dll", EntryPoint = "MsiRecordGetInteger", CharSet = CharSet.Unicode, ExactSpelling = true)]
700 public static extern int MsiRecordGetInteger(uint record, int field);
701
702 /// <summary>
703 /// PInvoke of MsiRectordSetInteger.
704 /// </summary>
705 /// <param name="record">MSI Record handle.</param>
706 /// <param name="field">Index of field to set integer value in.</param>
707 /// <param name="value">Value to set field to.</param>
708 /// <returns>Error code.</returns>
709 [DllImport("msi.dll", EntryPoint = "MsiRecordSetInteger", CharSet = CharSet.Unicode, ExactSpelling = true)]
710 public static extern int MsiRecordSetInteger(uint record, int field, int value);
711
712 /// <summary>
713 /// PInvoke of MsiRecordGetStringW.
714 /// </summary>
715 /// <param name="record">MSI Record handle.</param>
716 /// <param name="field">Index of field to get string value from.</param>
717 /// <param name="valueBuf">Buffer to recieve value.</param>
718 /// <param name="valueBufSize">Size of buffer.</param>
719 /// <returns>Error code.</returns>
720 [DllImport("msi.dll", EntryPoint = "MsiRecordGetStringW", CharSet = CharSet.Unicode, ExactSpelling = true)]
721 public static extern int MsiRecordGetString(uint record, int field, StringBuilder valueBuf, ref int valueBufSize);
722
723 /// <summary>
724 /// PInvoke of MsiRecordSetStringW.
725 /// </summary>
726 /// <param name="record">MSI Record handle.</param>
727 /// <param name="field">Index of field to set string value in.</param>
728 /// <param name="value">String value.</param>
729 /// <returns>Error code.</returns>
730 [DllImport("msi.dll", EntryPoint = "MsiRecordSetStringW", CharSet = CharSet.Unicode, ExactSpelling = true)]
731 public static extern int MsiRecordSetString(uint record, int field, string value);
732
733 /// <summary>
734 /// PInvoke of MsiRecordSetStreamW.
735 /// </summary>
736 /// <param name="record">MSI Record handle.</param>
737 /// <param name="field">Index of field to set stream value in.</param>
738 /// <param name="filePath">Path to file to set stream value to.</param>
739 /// <returns>Error code.</returns>
740 [DllImport("msi.dll", EntryPoint = "MsiRecordSetStreamW", CharSet = CharSet.Unicode, ExactSpelling = true)]
741 public static extern int MsiRecordSetStream(uint record, int field, string filePath);
742
743 /// <summary>
744 /// PInvoke of MsiRecordReadStreamW.
745 /// </summary>
746 /// <param name="record">MSI Record handle.</param>
747 /// <param name="field">Index of field to read stream from.</param>
748 /// <param name="dataBuf">Data buffer to recieve stream value.</param>
749 /// <param name="dataBufSize">Size of data buffer.</param>
750 /// <returns>Error code.</returns>
751 [DllImport("msi.dll", EntryPoint = "MsiRecordReadStream", CharSet = CharSet.Unicode, ExactSpelling = true)]
752 public static extern int MsiRecordReadStream(uint record, int field, byte[] dataBuf, ref int dataBufSize);
753
754 /// <summary>
755 /// PInvoke of MsiRecordGetFieldCount.
756 /// </summary>
757 /// <param name="record">MSI Record handle.</param>
758 /// <returns>Count of fields in the record.</returns>
759 [DllImport("msi.dll", EntryPoint = "MsiRecordGetFieldCount", CharSet = CharSet.Unicode, ExactSpelling = true)]
760 public static extern int MsiRecordGetFieldCount(uint record);
761
762 /// <summary>
763 /// PInvoke of MsiSetExternalUIW.
764 /// </summary>
765 /// <param name="installUIHandler">Specifies a callback function that conforms to the INSTALLUI_HANDLER specification.</param>
766 /// <param name="installLogMode">Specifies which messages to handle using the external message handler. If the external
767 /// handler returns a non-zero result, then that message will not be sent to the UI, instead the message will be logged
768 /// if logging has been enabled.</param>
769 /// <param name="context">Pointer to an application context that is passed to the callback function.
770 /// This parameter can be used for error checking.</param>
771 /// <returns>The return value is the previously set external handler, or zero (0) if there was no previously set handler.</returns>
772 [DllImport("msi.dll", EntryPoint = "MsiSetExternalUIW", CharSet = CharSet.Unicode, ExactSpelling = true)]
773 public static extern InstallUIHandler MsiSetExternalUI(InstallUIHandler installUIHandler, int installLogMode, IntPtr context);
774
775 /// <summary>
776 /// PInvoke of MsiSetpublicUI.
777 /// </summary>
778 /// <param name="uiLevel">Specifies the level of complexity of the user interface.</param>
779 /// <param name="hwnd">Pointer to a window. This window becomes the owner of any user interface created.
780 /// A pointer to the previous owner of the user interface is returned.
781 /// If this parameter is null, the owner of the user interface does not change.</param>
782 /// <returns>The previous user interface level is returned. If an invalid dwUILevel is passed, then INSTALLUILEVEL_NOCHANGE is returned.</returns>
783 [DllImport("msi.dll", EntryPoint = "MsiSetpublicUI", CharSet = CharSet.Unicode, ExactSpelling = true)]
784 public static extern int MsiSetInternalUI(int uiLevel, ref IntPtr hwnd);
785
786 /// <summary>
787 /// PInvoke of MsiSummaryInfoGetPropertyW.
788 /// </summary>
789 /// <param name="summaryInfo">Handle to summary info.</param>
790 /// <param name="property">Property to get value from.</param>
791 /// <param name="dataType">Data type of property.</param>
792 /// <param name="integerValue">Integer to receive integer value.</param>
793 /// <param name="fileTimeValue">File time to receive file time value.</param>
794 /// <param name="stringValueBuf">String buffer to receive string value.</param>
795 /// <param name="stringValueBufSize">Size of string buffer.</param>
796 /// <returns>Error code.</returns>
797 [DllImport("msi.dll", EntryPoint = "MsiSummaryInfoGetPropertyW", CharSet = CharSet.Unicode, ExactSpelling = true)]
798 public static extern int MsiSummaryInfoGetProperty(uint summaryInfo, int property, out uint dataType, out int integerValue, ref FILETIME fileTimeValue, StringBuilder stringValueBuf, ref int stringValueBufSize);
799
800 /// <summary>
801 /// PInvoke of MsiViewGetColumnInfo.
802 /// </summary>
803 /// <param name="view">Handle to view.</param>
804 /// <param name="columnInfo">Column info.</param>
805 /// <param name="record">Handle for returned record.</param>
806 /// <returns>Error code.</returns>
807 [DllImport("msi.dll", EntryPoint = "MsiViewGetColumnInfo", CharSet = CharSet.Unicode, ExactSpelling = true)]
808 public static extern int MsiViewGetColumnInfo(uint view, int columnInfo, out uint record);
809
810 /// <summary>
811 /// PInvoke of MsiViewExecute.
812 /// </summary>
813 /// <param name="view">Handle of view to execute.</param>
814 /// <param name="record">Handle to a record that supplies the parameters for the view.</param>
815 /// <returns>Error code.</returns>
816 [DllImport("msi.dll", EntryPoint = "MsiViewExecute", CharSet = CharSet.Unicode, ExactSpelling = true)]
817 public static extern int MsiViewExecute(uint view, uint record);
818
819 /// <summary>
820 /// PInvoke of MsiViewFetch.
821 /// </summary>
822 /// <param name="view">Handle of view to fetch a row from.</param>
823 /// <param name="record">Handle to receive record info.</param>
824 /// <returns>Error code.</returns>
825 [DllImport("msi.dll", EntryPoint = "MsiViewFetch", CharSet = CharSet.Unicode, ExactSpelling = true)]
826 public static extern int MsiViewFetch(uint view, out uint record);
827
828 /// <summary>
829 /// PInvoke of MsiViewModify.
830 /// </summary>
831 /// <param name="view">Handle of view to modify.</param>
832 /// <param name="modifyMode">Modify mode.</param>
833 /// <param name="record">Handle of record.</param>
834 /// <returns>Error code.</returns>
835 [DllImport("msi.dll", EntryPoint = "MsiViewModify", CharSet = CharSet.Unicode, ExactSpelling = true)]
836 public static extern int MsiViewModify(uint view, int modifyMode, uint record);
837
838 /// <summary>
839 /// contains the file hash information returned by MsiGetFileHash and used in the MsiFileHash table.
840 /// </summary>
841 [StructLayout(LayoutKind.Explicit)]
842 public class MSIFILEHASHINFO
843 {
844 [FieldOffset(0)] public uint FileHashInfoSize;
845 [FieldOffset(4)] public int Data0;
846 [FieldOffset(8)] public int Data1;
847 [FieldOffset(12)]public int Data2;
848 [FieldOffset(16)]public int Data3;
849 }
850 }
851}