Share via


Automating Project Pro to Project Server - GetWinProjLocation

In my last post I talked about connecting Project Pro to Project Server via automation. Connecting requires executing Project Pro with parameters to choose the Project Server and authentication method. But before you can execute Project Pro you must find its location on the machine. So what file are we looking for, winproj.exe. Many times people will install in the default location, c:\program files\Microsoft Office\Office XX. So you could check the default location. The first problem is are you sure the version you have installed so you know what XX is? Let's for a minute assume that you have Office 2003, so you know the folder is Office 11. That brings us to the second problem, if you don't find winproj in the default location where would you search next? For both of the pervious reasons it's best to search an alternate way, in the registry.

There are a number of places in the registry that have information on Project. One of our main goals needs to be maintaining version independence otherwise we have the same problems from searching in the file system. This rules out searching class ids or app ids, since they can change from version to version. Our best bet is to search the Project shell extension. A shell extension tells Windows what program to open when you double click a file. The shell extension to open a project file will tell us where winproj is. The location of the registry key is: HKEY_CLASSES_ROOT\MSProject.MPD\shell\Open\command. Below is a code snippet for retrieving the winproj location.

        public string GetWinProjectLocation()

        {

            RegistryKey rk = Registry.ClassesRoot.OpenSubKey("MSProject.MPD\\shell\\Open\\command");

            string location = (string)rk.GetValue("");

            rk.Close();

            return location.Substring(1, location.Length - 7);

        }

Once you retrieve the key value you need to trim the end of the key. You can use the returned value to start up Project Pro.