There must be a better way to do this. I have a Project Server plugin for the mpFx client application:
Selecting a project in the list view and clicking the button opens the project in WinProj. The problem is that you cannot open a project that exists in one project server instance programmatically if the user has WinProj open and connected to another instance of Project Server. Through automation, it is easy to determine which server the user is currently connected to:
If the user has WinProj open, I can grab an automation instance and check the current profile server against the server that my browser is currently pointed to. If the two don’t match, I indicate to the user that they must close WinProj and try again.
If WinProj is running and the user is connected to the same instance of WinProj, we simply open the project programmatically.
The challenge is to roll these different scenarios into one and solve the whole problem. Here is the basic layout of the method:
- Check to see if WinProj.exe is in the process list
- If it IS, then grab an instance and check the active profile server URL against the browser’s server URL
- The two match, open the project programmatically
- The two do not match, bail…
- If it IS NOT, then start WinProj. In my case, I have 6 possible candidate Project Server instances to choose from. I don’t have a default profile so starting WinProj doesn’t automatically log me in.
- Assuming WinProj started, wait for the user to login. If WinProj is busy and I attempt to automate it in anyway, you will see good old RPC_E_CALL_REJECTED exceptions
- Once WinProj accepts calls, I can check to see if the Project Server instance the user chose to login to matches and complete the circuit.
Here it is:
Here is a vide of it failing because I am already logged into a different instance of Project Server
And here is the final product: