none
Start MS Word application in safe mode RRS feed

  • Question

  • Hi guys

    I'm testing how to run MS Word application from VB.NET and I want to start the new instance in safe mode.

    I found this piece of code somewhere on internet and it works fine

    Dim startInfo As New ProcessStartInfo
    startInfo.FileName = "WINWORD.EXE"
    startInfo.Arguments= "/safe"
    Process.Start(startInfo)            

    But after the process started the instance of MS Word application I want to get the reference to be able working with the instance..Actually what I need to do is set the Displayalerts property to false.

    ' This is standard method that starts MS Word application
    'tempWordApp = New Word.Application
    tempWordApp.DisplayAlerts = false
    tempWordApp.Visible = true

    It must be easy though. Basicaly I'd like to do something like

    ' pseudo code !!
    tempWordApp = startInfo.GetObject() as Word.Application

    Thank you

    Pat


    Visual Studio 2010 Professional, Office 2007

    Tuesday, June 12, 2012 1:44 PM

Answers

  • I just checked, given start Word like command line  winword /safemode:

    The Word  COM object is not available at first, we cannot call Marshal.GetActiveObject("Word.Application"), but Outlook COM object is available initially.

    Manually, if we open COM addin dialog, the Word object gets ready.  Switch focus of Word doesn't help to this issue.

    So, if you start Word in safe mode, object model is not available.

    thanks,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Saturday, June 23, 2012 1:19 PM
    Moderator

All replies

  • use Marshal.GetActiveObject and cast it to Word interface

    Tuesday, June 12, 2012 1:55 PM
  • thank you for your help

    for some reason this line returns exception

    Dim tmp as Object = Marshal.GetActiveObject("Word.Application")

    Not sure why. e.g. if I try

    Dim tmp as Object = Marshal.GetActiveObject("Outlook.Application")

    it works fine.

    Of course, both applications are running at that time but the Word application throws exception

    Pat


    Visual Studio 2010 Professional, Office 2007

    Wednesday, June 13, 2012 8:41 AM
  • have you tried switching to other app, so word will loos focus after instantation with Process.Start? For example call Activate() on your app's window, assuming this is winforms app.
    Wednesday, June 13, 2012 9:03 AM
  • What's that Exception details?

    Forrest Guo | MSDN Community Support | Feedback to manager

    Thursday, June 14, 2012 1:35 PM
    Moderator
  • Sorry guys, vacation ...

    DamianD:

    Yes, I found an article on MSDN forum that says I have to give focus to something else (I tried Message Box as the article mentioned) but it doesn't work

    Forrest Guo:

    to be honest I'm not sure now, the application was just for testing to speed up our application so I tested some possibilities and finally I gave it up - it will be slow as it was but I'm pretty sure it was something with ActiveX object and the error number was something like -234578245  you know the strange long number if an ActiveX components throws an error

    Thanks guys


    Visual Studio 2010 Professional, Office 2007

    Monday, June 18, 2012 2:16 PM
  • I just checked, given start Word like command line  winword /safemode:

    The Word  COM object is not available at first, we cannot call Marshal.GetActiveObject("Word.Application"), but Outlook COM object is available initially.

    Manually, if we open COM addin dialog, the Word object gets ready.  Switch focus of Word doesn't help to this issue.

    So, if you start Word in safe mode, object model is not available.

    thanks,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Saturday, June 23, 2012 1:19 PM
    Moderator