Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2008-10-27
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 27

Expert Comment

ID: 22830399
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

ID: 22837739
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

ID: 22839969
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).
Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.


Author Comment

ID: 22844375
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.
LVL 27

Expert Comment

ID: 22851621
So how do you actually create an instance of PowerPoint in your program?

Author Comment

ID: 22853192
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

ID: 22857458
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
ID: 22862384
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Introduction This article is intended for those who are new to PHP error handling (  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

715 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