public void ExecuteApplication(PasswordEntryManager entryManager)
        {
            ExecutionSettings settings = entryManager.GetExecutionSettings();

            // Determine the values to use on native calls based on the impersonation settings.
            string domain   = settings.Domain;
            string username = settings.Username;

            Win32.LogonFlags logonFlags  = settings.NetOnly ? Win32.LogonFlags.LOGON_NETCREDENTIALS_ONLY : Win32.LogonFlags.LOGON_WITH_PROFILE;
            string           application = settings.Application;
            string           arguments   = settings.Arguments;
            string           workingDir  = string.IsNullOrWhiteSpace(settings.WorkingDir) ? null : settings.WorkingDir;

            // Create variables required for impersonation handling.
            IntPtr token = IntPtr.Zero;

            Win32.StartupInfo        startupInfo = new Win32.StartupInfo();
            Win32.ProcessInformation processInfo = new Win32.ProcessInformation();

            try
            {
                // Create process
                startupInfo.cb = Marshal.SizeOf(startupInfo);

                bool result = Win32.CreateProcessWithLogonW(
                    username,
                    domain,
                    entryManager.ProcessReplacementTags(settings.Password),
                    (uint)logonFlags,
                    application,
                    arguments,
                    0,
                    IntPtr.Zero,
                    workingDir,
                    ref startupInfo,
                    out processInfo);

                if (!result)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
            catch (Win32Exception ex)
            {
                string errorMessage = ex.Message;

                if ("A logon request contained an invalid logon type value".Equals(errorMessage))
                {
                    errorMessage = string.Concat(errorMessage, ". This is usually caused by attempting to use credentials for the network only but not specifying a domain.");
                }

                throw new ApplicationExecutionException(errorMessage, ex);
            }
            finally
            {
                if (processInfo.process != IntPtr.Zero)
                {
                    Win32.CloseHandle(processInfo.process);
                }

                if (processInfo.thread != IntPtr.Zero)
                {
                    Win32.CloseHandle(processInfo.thread);
                }
            }
        }