Пример #1
0
        /// <summary>
        ///     Starts Word
        /// </summary>
        private void StartWord()
        {
            if (IsWordRunning)
            {
                Logger.WriteToLog($"Word is already running on PID {_wordProcess.Id}... skipped");
                return;
            }

            Logger.WriteToLog("Starting Word");

            _word = new WordInterop.ApplicationClass
            {
                ScreenUpdating = false,
                DisplayAlerts  = WordInterop.WdAlertLevel.wdAlertsNone,
                DisplayDocumentInformationPanel = false,
                DisplayRecentFiles = false,
                DisplayScrollBars  = false,
                AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable,
                Visible            = false
            };

            _word.Options.UpdateLinksAtOpen    = false;
            _word.Options.ConfirmConversions   = false;
            _word.Options.SaveInterval         = 0;
            _word.Options.SaveNormalPrompt     = false;
            _word.Options.SavePropertiesPrompt = false;
            _word.Options.AllowReadingMode     = false;
            _word.Options.WarnBeforeSavingPrintingSendingMarkup = false;
            _word.Options.UpdateFieldsAtPrint   = false;
            _word.Options.UpdateLinksAtOpen     = false;
            _word.Options.UpdateLinksAtPrint    = false;
            _word.Options.DoNotPromptForConvert = true;
            _word.Options.LocalNetworkFile      = false;
            _word.Options.ConfirmConversions    = false;

            var captionGuid = Guid.NewGuid().ToString();

            _word.Caption = captionGuid;

            var processId = ProcessHelpers.GetProcessIdByWindowTitle(captionGuid);

            if (!processId.HasValue)
            {
                throw new OCConfiguration("Could not determine Word process by title");
            }

            _wordProcess = Process.GetProcessById(processId.Value);

            Logger.WriteToLog($"Word started with process id {_wordProcess.Id}");
        }