How to use an MS Office 2007 Interop COM object from an executable binary CGI file?

Posted on 2008-10-27
Last Modified: 2013-12-25

I am creating an online application that is conform to the CGI 1.1 standard and I am using C# to create the binary executable CGI. I am using Apache as my web server on a machine running MS Vista. The C# code is using the MS Office PowerPoint 2007 Interop capabilities in order to modify a PPT file dynamically from the webpage.

I tried the code to modify the PPT file separately and it works fine but when I integrate it with the CGI executable and run it from my web frontend, MS PowerPoint runs and pops up an error message saying: "Microsoft Office PowerPoint has not been installed for the current user. Please run setup to install the application."

However, when I run PowerPoint manually, I don't get this error message.

I tried to reinstall Office 2007 Home and Student but with no success.

I have Administrator permissions for my current user.

If I had to guess, I think my problem is that Apache starts the CGI executable with some other user that the one that I am currently logged in into. But I don't know how to check if I guessed right and I don't know how to fix the problem.

Thank you.
Question by:MerlinMM3
  • 5
  • 3
LVL 27

Expert Comment

Comment Utility
1) Could you first of all post the shebang line from your CGI script file?

2) I presume that in the http.conf file you have the CGI directory marked with ExecCGI as in :-

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/CGI-bin">
    AllowOverride None
    Options None    <-- change this line to 'Options ExecCGI'.
    Order allow,deny
    Allow from all

and have an AddHandler statement for cgi?

3) Lastly I presume you installed Apache as default, in which case it runs (and its CGI) under the local system account which has no priveliges. You might need to create a special account for Apache and run it there. This tutorial should help (see the last part of the paragraph "Running Apache as a Service"

Author Comment

Comment Utility
There is no shebang line since my CGI file is an binary executable. Also, I set up Apache by adding the option ExecCGI just like you specified. I set up a default directory for CGIs. However, I didn't put an AddHandler to my config but chose to use a .htaccess file instead.

That being said, my problem is not that the CGI is not executed. The CGI does return a properly generated HTML page. The problem occurs when the CGI executes PowerPoint. PowerPoint is launched but pops up the error message I mentioned in my first post.

I searched the net for this error message and found that some people experienced this issue when first launching Office for the first time after installation. There is actually a KB article released by Microsoft about this. But my problem is somewhat different. When I run PowerPoint manually (I double click the icon on the desktop), it runs just fine and I can start using it.

But when my CGI runs PowerPoint using Microsoft.Office.Interop.PowerPoint (version 12.0), PowerPoint pops up the evil message saying that PowerPoint is not installed for the current user.

I thought that maybe my CGI was launching PowerPoint using a Guest user account instead of using the user on which Apache was currently running on but I tried displaying the name of the Windows user executing the CGI and it really was the user with Administrator rights.

Despite of that, I think it has to do with permissions but I just don't know how to fix this. Maybe it's an Interop specific problem and maybe it has to do with the Home and Student edition of my Office.
LVL 27

Expert Comment

Comment Utility
OK, I just wanted to be sure Apache was OK.

It seems like, since you mention it is a Student edition, that it might only allow itself to start from the desktop. Try putting the desktop command into a .bat file and execute that from a cmd box (DOS box).

Author Comment

Comment Utility
That was a good suggestion but sadly, that didn't work.

The problem is I can't see what the Target is for my desktop icon as it is hidden. See the attached picture file to see exactly how.

So I tried executing PowerPoint
- from the Windows Explorer (and my user have Administrative rights).
- from the automatically generated icon on the desktop
- from the custom-made icon on the desktop
- from the command prompt
- from a batch file started from the desktop
- from a batch file started from the command prompt

I tried the "Run as Administrator" option in the Windows Explorer and in my custom-made icon on the desktop. The option is not available for the automatically generated icon.
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

LVL 27

Expert Comment

Comment Utility
So how do you actually create an instance of PowerPoint in your program?

Author Comment

Comment Utility
I create my CGI binary in C#.
In my project, I add a reference to "Microsoft PowerPoint 12.0 Object Library" (TypeLib Version 2.9).
Then I use code that is similar to the attached snippet.
using Microsoft.Office.Interop;

PowerPoint.Application app = new PowerPoint.Application();

PowerPoint.Presentation presentation = app.Presentations.Open(filename, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue);

PowerPoint.Slide slide = presentation.Slides[0];


Open in new window


Author Comment

Comment Utility
Now I'm thinking that the problem might be caused by the environment variables. When executing the CGI binary file, the environment vars are not the same as when I start it in the command prompt. Maybe launching PowerPoint from a CGI messes it up. I'll investigate this today and come back to you for the results.

Accepted Solution

MerlinMM3 earned 0 total points
Comment Utility
OK, I finally found the answer to my problem!!!!

Just as last suspected, the problem was related to the environment variables. When the CGI program is executed by the web server, the environment variables are different from the ones in the command prompt. In most cases, we don't care because CGI programs do not need system environment variables. But, in this case, PowerPoint required one that was not set.

To resolve this issue, what I did was setting my system environment variables at the beginning of the CGI program code using the following C# method:

I added such a statement for each of my system environment variables. From there on, PowerPoint didn't give me that evil message anymore.

After further investigations, I found that setting only "SystemDrive" at the beginning of my CGI program seemed a sufficient solution.

Now that I know the solution, I remember that executing my CGI program had the side-effect of creating a folder %SystemDrive% in the local directory of my CGI program. I didn't pay much attention to it, but now I see that if any folder name of the form %folder_name% appears in the local directory, it is likely that a system environment variables is not set.

Also, instead of modifying the CGI program, an alternative solution could be to configure Apache to pass the system environment variable to the CGI programs, but I have very little experience in configuring web server. For those interested in doing so, look for "PassEnv" in your favorite search engine.
// Add this line at the beginning of the C# code

System.Environment.SetEnvironmentVariable("SystemDrive", "C:");

Open in new window


Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at (http://www.experts-ex…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now