Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MsiOpenDatabase

94 views
Skip to first unread message

Bill Rowell

unread,
Jul 29, 2004, 10:48:52 PM7/29/04
to
Hi,

I have the following code to open an existing MSI file:

PMSIHANDLE hMSI = 0;
UINT uiRetVal = 0;
uiRetVal = MsiOpenDatabase(TEXT(lpOrigFile), TEXT(lpNewFile), &hMSI);

where lpOrigFile and lpNewFile are const char*. lpOrigFile is a file path
that exists on the file system and lpNewFile is a file path to a new file to
be created on the file system (its path exists, though the file does not).

MsiOpenDatabase always returns ERROR_OPEN_FAILED. I've followed the
examples at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/a_database_and_patch_example.asp

and figured I was doing the right thing. Is there something else I'm
forgetting like setting up the original MSI file to be edited, etc.?

Regards,
Bill


Rich [Microsoft Windows Installer MVP]

unread,
Jul 30, 2004, 12:14:09 AM7/30/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code
<#HPtA$ddEHA...@tk2msftngp13.phx.gbl> thusly:

>PMSIHANDLE hMSI = 0;
>UINT uiRetVal = 0;
>uiRetVal = MsiOpenDatabase(TEXT(lpOrigFile), TEXT(lpNewFile), &hMSI);

The TEXT() macro is only for character or string constants, it does
not do character set conversion.

Either use the A or W form explicitly, depending on your string type,
or read up on how to use the A2T, etc., macros in <atlbase.h>.
--
"The Direct3D Graphics Pipeline"-- code samples, sample chapter, FAQ:
<http://www.xmission.com/~legalize/book/>
Pilgrimage: Utah's annual demoparty
<http://pilgrimage.scene.org>

Bill Rowell

unread,
Jul 30, 2004, 9:13:12 AM7/30/04
to
Ok, thanks. I tried hardcoded strings too with the same code and it failed.
So I'm not so sure that will solve my problem.

-Bill

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>
wrote in message news:uSQiqued...@TK2MSFTNGP10.phx.gbl...

Rich [Microsoft Windows Installer MVP]

unread,
Jul 30, 2004, 10:06:52 AM7/30/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code

<Ovpu4bjd...@TK2MSFTNGP12.phx.gbl> thusly:

>Ok, thanks. I tried hardcoded strings too with the same code and it failed.
>So I'm not so sure that will solve my problem.

Post the code that fails with the hardcoded strings.

Bill Rowell

unread,
Aug 2, 2004, 2:02:55 PM8/2/04
to
So this fails:

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:#pt$35jdE...@TK2MSFTNGP11.phx.gbl...

Bill Rowell

unread,
Aug 2, 2004, 2:04:38 PM8/2/04
to
So this fails:

uiRetVal = MsiOpenDatabaseA("C:\\Orca.msi", MSIDBOPEN_DIRECT, &hMSI);

and returns 1601, which I've looked up to be ERROR_INSTALL_SERVICE_FAILURE,
which according to the comment in msi.h means that the installer service
could not be accessed. I'm not sure why that would happen.

I'm running the code on Windows 2003.

Regards,
Bill

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:#pt$35jdE...@TK2MSFTNGP11.phx.gbl...

Rich [Microsoft Windows Installer MVP]

unread,
Aug 2, 2004, 2:17:39 PM8/2/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code

<OFOY4sLe...@TK2MSFTNGP09.phx.gbl> thusly:

>So this fails:
>
>uiRetVal = MsiOpenDatabaseA("C:\\Orca.msi", MSIDBOPEN_DIRECT, &hMSI);

What is the declaration of hMSI?
The file exists at that path?
Do you have the file open in an MSI editor (Orca, etc.) while trying
to make this call?
Can you open the file in Orca?
Can you open the file in MSIDBOPEN_TRANSACT mode?

Bill Rowell

unread,
Aug 2, 2004, 2:25:12 PM8/2/04
to
It happens on my Windows 2000 box as well.

hMSI is declared as MSIHANDLE, but declaring it as PMSIHANDLE gives the same
results.

The file does indeed exist there and no, it is not open by any other
application. Yes, I can open it in Orca. This will happen on both my
Windows 2000 and Windows 2003 systems no matter what MSI file I give
MsiOpenDatabase.

It also happens if I use MSIDBOPEN_TRANSACT.

I've pretty much tried everything I've found online...

Regards,
Bill

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:OvI4$zLeEH...@TK2MSFTNGP12.phx.gbl...

Rich [Microsoft Windows Installer MVP]

unread,
Aug 2, 2004, 3:00:58 PM8/2/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code

<#rOMQ4Le...@TK2MSFTNGP10.phx.gbl> thusly:

>The file does indeed exist there and no, it is not open by any other
>application. Yes, I can open it in Orca. This will happen on both my
>Windows 2000 and Windows 2003 systems no matter what MSI file I give
>MsiOpenDatabase.

Can you open it from script?

Do 'wirunsql.vbs orca.msi "SELECT * FROM `File`"'

Bill Rowell

unread,
Aug 2, 2004, 3:25:34 PM8/2/04
to
So, I had been doing this from C++ code.

I just tried it in InstallScript and it seems to be working...I'll go with
that for a little while and see where it takes me.

Regards,
Bill

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:O53lMMMe...@TK2MSFTNGP09.phx.gbl...

Phil Wilson

unread,
Aug 2, 2004, 3:42:45 PM8/2/04
to
Are you building with recent header files and lib files from the Platform
SDK? VS has out-of-date ones.
--
Phil Wilson [MVP Windows Installer]
----
"Bill Rowell" <bi...@donotspam.com> wrote in message
news:#rOMQ4Le...@TK2MSFTNGP10.phx.gbl...

Bill Rowell

unread,
Aug 2, 2004, 3:49:22 PM8/2/04
to
Yeah, I'm using Microsoft's Feb. 2003 SDK.

-Bill

"Phil Wilson" <Phil....@unisys.spamcom> wrote in message
news:OcTFjjM...@TK2MSFTNGP11.phx.gbl...

Rich [Microsoft Windows Installer MVP]

unread,
Aug 2, 2004, 3:52:33 PM8/2/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code

<OkWo8ZMe...@TK2MSFTNGP10.phx.gbl> thusly:

>I just tried it in InstallScript and it seems to be working...I'll go with
>that for a little while and see where it takes me.

You don't need InstallScript for this.

Use VBScript or JScript.

If it works from VBS/JS, then it sounds like you might have
out-of-date headers and/or you're linking to out-of-date libraries.

Bill Rowell

unread,
Aug 2, 2004, 4:31:12 PM8/2/04
to
Well, the code executes without errors in InstallScript, however it doesn't
actually modify the MSI file that I need to modify.

I don't think its out of date headers or libraries. I'm using the Feb. 2003
Platform SDK...that should be up to date enough.

Regards,
Bill

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:#KYaBpMe...@TK2MSFTNGP10.phx.gbl...

Rich [Microsoft Windows Installer MVP]

unread,
Aug 2, 2004, 4:39:53 PM8/2/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code

<uXITo#MeEHA...@TK2MSFTNGP09.phx.gbl> thusly:

>Well, the code executes without errors in InstallScript,

Are you confusing InstallScript with VBScript?

You don't need InstallScript. I would recommend not using it.

>however it doesn't
>actually modify the MSI file that I need to modify.

Can you modify the database with wirunsql?

Bill Rowell

unread,
Aug 2, 2004, 4:52:07 PM8/2/04
to
No, I'm not confusing the two. <G>

And yes, wirunsql.vbs returns some stuff using that SELECT statement.

I'd avoid the InstallScript if the C++ calls worked, but they weren't. The
InstallScript ones seem to execute fine (no errors), however my MSI file
doesn't retain any changes that were made by actually executing the
InstallScript.

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:OAwKeDNe...@TK2MSFTNGP11.phx.gbl...

Bill Rowell

unread,
Aug 2, 2004, 5:08:23 PM8/2/04
to
So, I tried a different approach. I thought I'd let MsiOpenDatabase open an
existing file, and output a new one. Calling something like:

MSIHANDLE hMSI;
uiRetVal = MsiOpenDatabase(lpOldFile, lpNewFile, &hMSI);

So, this seems to work alright, creating a new file and writing the new
values I want in the table I'm modifying. However, the new MSI package is
about half the size as the old one and it won't work when you try and run
it. I read somewhere that some stream is not available for writing when you
do this, but I didn't think that it would leave out data.

I was under the impression that MsiOpenDatabase if called like this would
open the existing file (lpOldFile) and write existing data and anything you
change to the new file (lpNewFile).


"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:OAwKeDNe...@TK2MSFTNGP11.phx.gbl...

Rich [Microsoft Windows Installer MVP]

unread,
Aug 2, 2004, 5:22:22 PM8/2/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code

<OGqVUKNe...@TK2MSFTNGP11.phx.gbl> thusly:

>And yes, wirunsql.vbs returns some stuff using that SELECT statement.

Fine. But I asked:

>> Can you modify the database with wirunsql?

Use an UPDATE query.

Bill Rowell

unread,
Aug 2, 2004, 7:11:56 PM8/2/04
to
I can try that, but what does modifying the database have to do with opening
it in the first place?

With the first snippets I sent, I wasn't getting past opening the file.

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:#wsZNbNe...@tk2msftngp13.phx.gbl...

Rich [Microsoft Windows Installer MVP]

unread,
Aug 2, 2004, 7:52:16 PM8/2/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code

<eofbcYOe...@tk2msftngp13.phx.gbl> thusly:

>I can try that, but what does modifying the database have to do with opening
>it in the first place?

It will tell me if you can modify the database at all or if the
problem is somewhere in the code you're compiling to make changes.

>With the first snippets I sent, I wasn't getting past opening the file.

Putting more suspicion on your process, not the API. This API call is
so basic (every tool and piece of MSI uses it), that if it really
didn't work, then neither would Orca, etc.

Bill Rowell

unread,
Aug 2, 2004, 8:03:27 PM8/2/04
to
I'm sure its the process, not the API.

I've tried two things:

1.) Using hr = MsiOpenDatabase(lpOldFile, lpNewFile, &hMSI) to create a new
MSI packages based on the old one. I think this doesn't work so well
because the result file ends up half the size of the original one (I think
it has something to do with the summary information being missing)

2.) I copy the original MSI file to somewhere else on the system. Then I
try and call MsiOpenDatabase on the new file. I've tried MSIDBOPEN_TRANSACT
and MSIDBOPEN_DIRECT and neither work. I copy the file using XCopyFile in
InstallScript. I haven't tried copying it by some other means as I don't
really think that is the issue.

My frustration here is that there doesn't seem to be any documentation or
information about MsiOpenDatabase returning error code 1601. All the
information I have found doesn't really apply to my situation.

Regards,
Bill

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:u5rP#uOeEH...@TK2MSFTNGP09.phx.gbl...

Bill Rowell

unread,
Aug 2, 2004, 8:16:07 PM8/2/04
to
I was able to modify that MSI file using that script.

Regards,
Bill

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:u5rP#uOeEH...@TK2MSFTNGP09.phx.gbl...

Bill Rowell

unread,
Aug 3, 2004, 9:28:17 AM8/3/04
to
Using MSIDBOPEN_READONLY in MsiOpenDatabase works as well from my C++ code.

Regards,
Bill

"Bill Rowell" <bi...@donotspam.com> wrote in message

news:uT6pT8Oe...@TK2MSFTNGP09.phx.gbl...

Bill Rowell

unread,
Aug 3, 2004, 10:08:54 AM8/3/04
to
So, I found this searching on google groups:

http://groups.google.com/groups?q=MsiOpenDatabase&start=20&hl=en&lr=&ie=UTF-8&selm=%23%23D%24telmCHA.1536%40tkmsftngp02&rnum=29

Tried doing the MsiOpenDatabase from an exe file from my installer and it
works fine. So again, I'm going to go with this and see where it takes
me...

Quite a lot of trial and error with this stuff...

"Rich [Microsoft Windows Installer MVP]" <legaliz...@mail.xmission.com>

wrote in message news:u5rP#uOeEH...@TK2MSFTNGP09.phx.gbl...

Rich [Microsoft Windows Installer MVP]

unread,
Aug 3, 2004, 11:52:56 AM8/3/04
to
[Please do not mail me a copy of your followup]

"Bill Rowell" <bi...@donotspam.com> spake the secret code

<OESgqNWe...@TK2MSFTNGP09.phx.gbl> thusly:

>Tried doing the MsiOpenDatabase from an exe file from my installer and it

>works fine. [...]

Well now its starting to sound like you're only telling me half the
story.

Are you trying to modify a database while inside an install?

0 new messages