unable to initialize PIA of application class (Project Pro 2003)

S

Stephan Steiner

Hi

I had to write a C# application to automate project professional 2003.

Here's how I start the client:

proc = Process.Start(applicationPath, ApplicationArguments);

Where applicationpath is "C:\Program Files\Microsoft
Office\OFFICE11\WINPROJ.EXE"

and ApplicationArguments is /s http://projectserver/ProjectServer /u login
/p password

After a predefined timeout, I then initialize PIA:

application = new MSProject.Application();
application.AutomationSecurity =
Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
application.Calculation =
Microsoft.Office.Interop.MSProject.PjCalculation.pjAutomatic;
application.MacroVirusProtection = false;
application.DisplayAlerts = false;
application.DisplayWizardErrors = false;

I've tested the code on two test projects in the productive environment and
it worked out fine. I even ran the code on the machine it is intended to
run - though using another account on the project server.

I have the whole PIA code wrapped in a try / catch. Now when we went
productive, I started catchig errors in PIA initialization:

unable to initialize PIA of application class: Call was rejected by callee.
(Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))


Upon further investigation, it turned out that when the project client was
started, it came up with two error message boxes with the following content:

Project cannot open the file.

Check that the file name and path are correct.

Check that the file format is recognized by Project.

Project files saved in an version earlier than Microsoft Project 98 can't be
opened.

If your file is from an earlier version, open it in that version, click Save
as (File menu), and save in MPX Format. Open the MPX file in the current
version of Project. When you use this method, project data is imported, but
formatting is lost.

That popup comes up once, wants you to click OK, then the same popup comes
up again.


When you manually click away these two popups, the code then runs fine (up
until the next time you have to start the project client) so I figure the
whole PIA errors are due to project not being fully initialized yet.

So I figured I could probably retrace the problem by just starting the
project client manually from the commandline, using the same arguments in my
code. However, if I do that, the error does not come up. Note that I'm doing
this under the same user account as the user account under which my software
runs. And now I'm at a loss.. why do I get these two warning messages only
when I launch the project client from my code, and how can I avoid them
(other then sending keystrokes and unreliable hacks like that) so that the
whole process can run without any manual intervention.

Regards
Stephan
 
S

Stephan Steiner

Unfortunately, we have special non Domain users for these tasks.

We do have projects where we have multiple people create assignments,
publish and approve hours. If we do this using the user specific accounts
for the people who do these tasks, we get one hell of a mess in the project
plan, with different people responsible for different tasks and all kinds of
weird effects in approving hours (remaining work changes all the time).
Hence, we have created special accounts for those tasks and republished all
assignments under these tasks. Now we don't have all those sideeffects
anymore, but they are local project server accounts and that's just how it
is.

And, the problem only comes up if I run project client from within my app,
not from the shell.

I've managed to get rid of the first popup via AppActivate followed by
Sendkey (can you say ugly hack that's bound to bite me in the behind sooner
or later) and I'll add a window checker to make sure I only run that code if
necessary, but I'd really rather just find a way to get rid of the popups
altogether.

Regards
Stephan
 
S

Stephan Steiner

I really hate myself for doing this (bump in a manner of speaking).. but I'm
getting outright desperate.

The popup only comes up when I launch the app from my code.

Then, it gets worse: I have written several approaches to identifying teh
popup, activate it, and "click it away", using AppActivate on the processID,
then SendKeys, and using interop with native code (FindWindow(ex),
GetDlgCtrlID to find the button, and PostMessage to click it away.

Both approaches work like a charm.. there's just one tiny problem: it works
as long as somebody sits in front of the machine and does nothing. If I RDP
into the machine, I also see it working. If however, I end the RDP and then
at some point the app runs, I don't get the popups.. when project client
launches, it stays in the background blinking in the taskbar.. and unless
you activate it, the popup errors never come up. So.. I figured I'd just use
GetForegroundWindow and SetForegroundWindow to see which application is
active, and if it's not project client, activate it, go to sleep for a few
seconds to give the popup time to come up, and then I should be able to
click it away.

However, not even that works.. looking at traces I see that the application
notes that project client isn't the application in the foreground, so it
calls SetForegroundWindow which works out just fine, but then
GetForegroundWidnow returns 0 again.. so project client isn't the app on top
of the screen, and hence no popups and I can never proceed in loading the
project (initializing PIA gets me the usual error).

I feel like I'm at the end of my rope here.. the app does need to run
unattended and I can't RDP in every time I get a warning email to see the
app run properly one time, disconnect, and wait for the next alarm email.

If anybody has any idea on how I can reliably prevent ANY and all popup
errors that might appear when starting project client, I'd be extremely
grateful.

Regards
Stephan
 
R

Rod Gill

Have you tried setting the Status Manager field to prevent the "mess"?

What happens if you increase the timeout?

In VBA I loop attempting to connect to the new Project Application Object
until successful or a timeout occurs. This works well. I don't use C# so
what equivalent C# code is there?

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
S

Stephan Steiner

In fact I'm doing the same as you in VBA.. I have a loop with a timeout
trying to initialize the application object.

The problem when running it unattended is that the project client will never
successfully start.. it starts, sits there minimized blinking in the
taskbar.. if I activate it, it brings up the two error popups. When the
screen is locked, I cannot bring the window to the foreground so it shows me
the two popups and without clicking those two popups away, I can loop and
try to intialize the application object until kingdom come.

Where would I find the status manager field?

Regards
Stephan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top