public static RM_APP_TYPE GetProcessType(Process proc)
        {
            uint   handle;
            string key = Guid.NewGuid().ToString();

            uint res = RmStartSession(out handle, (uint)0, key);

            if (res != 0)
            {
                throw new ApplicationException("Could not begin restart session. ");
            }

            try
            {
                uint pnProcInfoNeeded = 0, pnProcInfo = 0,
                     lpdwRebootReasons = RmRebootReasonNone;

                RM_UNIQUE_PROCESS uniqueprocess = new RM_UNIQUE_PROCESS();
                uniqueprocess.dwProcessId = proc.Id;
                System.Runtime.InteropServices.ComTypes.FILETIME ft = FileTimeFromDateTime(proc.StartTime);
                uniqueprocess.ProcessStartTime = ft;

                res = RmRegisterResources(handle, 0, null, 1, ref uniqueprocess, 0, null);

                if (res != 0)
                {
                    throw new ApplicationException("Could not register resource.");
                }

                res = RmGetList(handle, out pnProcInfoNeeded, ref pnProcInfo, null,
                                ref lpdwRebootReasons);
                if (res == ERROR_MORE_DATA)
                {
                    RM_PROCESS_INFO[] processInfo = new RM_PROCESS_INFO[pnProcInfoNeeded];
                    pnProcInfo = pnProcInfoNeeded;

                    res = RmGetList(handle, out pnProcInfoNeeded, ref pnProcInfo,
                                    processInfo, ref lpdwRebootReasons);
                    if (res == 0)
                    {
                        if (pnProcInfo == 0)
                        {
                            throw new ApplicationException("Process not found");
                        }

                        return(processInfo[0].ApplicationType);
                    }
                    else
                    {
                        throw new ApplicationException("Could not list processes");
                    }
                }
                else if (res != 0)
                {
                    throw new ApplicationException("Failed to get size of result.");
                }
            }
            finally
            {
                RmEndSession(handle);
            }
            throw new ApplicationException("Process not found");
        }
 public static extern UInt32 RmRegisterResources(UInt32 dwSessionHandle,
                                                 UInt32 nFiles, string[] rgsFilenames, UInt32 nApplications,
                                                 ref RM_UNIQUE_PROCESS rgApplications, UInt32 nServices, string[] rgsServiceNames);