473,404 Members | 2,137 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,404 software developers and data experts.

How to fetch MSIHANDLE for the current instance of the installer in Installer class.

I have a setup project in Visual Studio 2008 with Custom Action class. I have to execute the msi on command line using msiexec /i SetupProject.msi /qb /l* out.txt command. The task is to write custom messages to the log file. This can be done by MsiProcessMessage function from Windows Installer API. To achieve this I have downloaded the C# wrapper class posted on CodeProject.com (http://www.codeproject.com/csharp/msiinterop.asp) that provides a C# interface to the common Windows Installer APIs.

Now the problem is, I am not able to get the MSIHANDLE for the current instance of the installer in custom action class using that wrapper class. My function Write to log goes like this,
private void WriteToLogFile(string sMessage)
{
IntPtr hInstall = IntPtr.Zero;
IntPtr hRec;
uint lCount;

MsiInterop.MsiOpenPackage(@" D:\SetupProject.msi", out hInstall);

//Validate the passed-in string
if (sMessage.Length == 0)
{
return;
}


//Create a record with only one field
hRec = MsiInterop.MsiCreateRecord(1);

//Handle problem creating record
if ((int)hRec == 0)
{
return;
}

//Create the full message
//szFullMessage = STARS + szMessage;

//Set that one field to the passed-in string
MsiInterop.MsiRecordSetString(hRec, 1, sMessage);

//Set the formatting string to NULL
MsiInterop.MsiRecordSetString(hRec, 0, "[1]");

//Get length of message to pass to MsiFormatRecord
lCount = (uint)sMessage.Length;

//Format the record to get rid of the '1.'
MsiInterop.MsiFormatRecord(hInstall, hRec, sMessage, ref lCount);

//Handle processing the message
MsiInterop.MsiProcessMessage(hInstall, MsiInstallMessage.Info, hRec);
}

In the above function, it neither takes any handle to the installer nor writes any thing to the log file.

Thanks in advance,
Yogita
Mar 29 '10 #1
1 4153
Gave the wrong link above for Windows API. It is http://www.codeproject.com/KB/cs/msi...px?msg=1377357

Waiting for your valuable solution
Mar 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this...
6
by: Andre Meyer | last post by:
Hi all I have been searching everywhere for this, but have not found a solution, yet. What I need is to create an object that is an instance of a class (NOT a class instance!) of which I only...
1
by: ChinStrap | last post by:
I am sorry if this is obvious, but I am not seeing it. How would I go about creating a new type that is of the same type as a class sent into the function? new = foo.__init__() refers to the...
17
by: bengamin | last post by:
Hi, I have a C# class and two instance of the class; the class have some property. I want to compare the property value of the two instance How should i do? override == ? use delegate ?
5
by: Adda | last post by:
Is it possible to set a variable to a current instance of a running object without using the New keyword? Here is my situation. I have been trying to add a record to a dataset on a Parent Mdi...
8
by: kevin | last post by:
I have a form and in the form I have a sub that uses a class I instantiate using visual basic code: Public oCP As New Rs232 'instantiate the comm port I need to share this sub with...
2
by: News.microsoft.com | last post by:
I have a service on which I can make a request that returns an object of type Person (for example). I would like to add some additional properties to this class without modifing the Person class. ...
8
by: news.microsoft.com | last post by:
How do I get the class name for a current instance. For example, if I want to know the Class Name for the current form, how do I get this programatically. Thanks
6
by: JB | last post by:
Hi All, I'm building a DLL that can be used by several applications. I'd like to have one single instance of a Class stored in my DLL that would be ("shared") by all the applications using that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.