none
Error: "The server is not available. Contact your administrator if this condition persists." RRS feed

  • Question

  • I am trying to automate Outlook from a VB Forms app. If I have an instance of Outlook running, everything works fine. If Outlook is not already running, the code throws the following exception when trying to automatically start Outlook: "The server is not available. Contact your administrator if this condition persists."

    Below is the code, most of which is taken from MS examples. I've tried setting the "create new session" parameter both to True and to False, and it makes no difference.

     

    Dim outlookProcesses As Integer

    ' Note that some variables have been previously dimensioned outside this example

     

    outlookProcesses =

    Process.GetProcessesByName("OUTLOOK"

    ).GetLength(0)

     

    If outlookProcesses > 0 Then

    ' Use the running copy of Outlook if it exists

     

    mobjOL = DirectCast(Marshal.GetActiveObject("Outlook.Application"), Outlook.Application

    )

    mobjNS = mobjOL.Session

    mobjNS.Logon(AppSetting.

    OutlookMail.MailboxName, AppSetting.OutlookMail.MailboxPassword, False, False)

    ' Last param says not to create a new session

     

    Else

    ' Create a new instance of Outlook if one is not running, and log onto the default profile

    mobjOL =

    New

    Application

    mobjNS = mobjOL.GetNamespace(

    "MAPI"

    )

    mobjNS.Logon(AppSetting.

    OutlookMail.MailboxName, AppSetting.OutlookMail.MailboxPassword, False, True)

    ' Last param says whether to create a new session

     

    End If


    Robert Quattlebaum
    Wednesday, January 18, 2012 3:48 PM

Answers

  • System.Activator.CreateInstance().
     
    About the only other thing I can think of would be to open a support case with MS and see what comes of that. Of course unless you have MSDN support incidents available or it proves to be an Outlook bug that would cost you.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "vsk9" <=?utf-8?B?dnNrOQ==?=> wrote in message news:52fcd33f-caed-4f45-a924-36050b722cea...

    If you will note in the Else clause of my code -- the branch that is executing -- I am already using GetNameSpace("MAPI"). I had also previously tried using Logon("", "", false, false), but that did not work, either.

    Also, in that same branch of code, note that I'm already using mobjOL = new Application (where Application resolves to Outlook.Application). But, just for grins, I tried it explicitly per your note, to no avail.

    I was not able to try CreateInstance, as I cannot get Visual Studio to recognize that command.

    I'm wondering why this is not a very common feature to try, and why there would not be sample code somewhere that shows how to do it.

    I don't know if this is of any significance, but I've noted that every time I make the call to Logon, an instance of Outlook is actually fire up and continues to run until I kill it in Task Manager. It prevents other copies from running until I kill it, yet it seems to be in no condition to respond to calls since I get exceptions thrown in try to access it. I'm going to search for any references to similar code as I am getting nowhere.


    Robert Quattlebaum

    Ken Slovak MVP - Outlook
    Thursday, January 19, 2012 7:55 PM
    Moderator

All replies

  • Most of the time I've seen that with managed code there's some mismatch with the requested permissions between Outlook and how it was started and the permissions requested by the outside code. Are you setting up your manifests and so on to request asInvoker permissions for everything, or does something request admin permissions?

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "vsk9" <=?utf-8?B?dnNrOQ==?=> wrote in message news:cf961c6e-68eb-4ea1-b3b5-fdf9a0fe1f13...

    I am trying to automate Outlook from a VB Forms app. If I have an instance of Outlook running, everything works fine. If Outlook is not already running, the code throws the following exception when trying to automatically start Outlook: "The server is not available. Contact your administrator if this condition persists."

    Below is the code, most of which is taken from MS examples. I've tried setting the "create new session" parameter both to True and to False, and it makes no difference.

     

    Dim outlookProcesses As Integer

    ' Note that some variables have been previously dimensioned outside this example

     

    outlookProcesses =

    Process.GetProcessesByName("OUTLOOK"

    ).GetLength(0)

     

    If outlookProcesses > 0 Then

    ' Use the running copy of Outlook if it exists

     

    mobjOL = DirectCast(Marshal.GetActiveObject("Outlook.Application"), Outlook.Application

    )

    mobjNS = mobjOL.Session

    mobjNS.Logon(AppSetting.

    OutlookMail.MailboxName, AppSetting.OutlookMail.MailboxPassword, False, False)

    ' Last param says not to create a new session

     

    Else

    ' Create a new instance of Outlook if one is not running, and log onto the default profile

    mobjOL =

    New

    Application

    mobjNS = mobjOL.GetNamespace(

    "MAPI"

    )

    mobjNS.Logon(AppSetting.

    OutlookMail.MailboxName, AppSetting.OutlookMail.MailboxPassword, False, True)

    ' Last param says whether to create a new session

     

    End If


    Robert Quattlebaum

    Ken Slovak MVP - Outlook
    Wednesday, January 18, 2012 4:29 PM
    Moderator
  • I'm not familiar with setting up asInvoker permissions in the manifest, or with requesting admin permissions. Can you elaborate on how to go about this?
    Robert Quattlebaum
    Wednesday, January 18, 2012 8:05 PM
  • When you compile your addin look under the \bin\Release or \Debug folders, you should see a .manifest file there. A typical one would look something like this, where I've blacked out the public key token and addin name:
     
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
      <noInheritable />
      <assemblyIdentity
          processorArchitecture="*"
          type="win32"
          name="MyCompany.Outlook.MyAddinName"
          version="1.0.0.0"
          publicKeyToken="XXXXXXXXXXXX" />
      <description>MyCompany Outlook COM Addin Manifest</description>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges>
            <requestedExecutionLevel
                level="asInvoker"
                uiAccess="false" />
          </requestedPrivileges>
        </security>
      </trustInfo>
    </assembly>

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "vsk9" <=?utf-8?B?dnNrOQ==?=> wrote in message news:332d4182-9b49-4f18-a65d-af21d25fab07...
    I'm not familiar with setting up asInvoker permissions in the manifest, or with requesting admin permissions. Can you elaborate on how to go about this?
    Robert Quattlebaum

    Ken Slovak MVP - Outlook
    Wednesday, January 18, 2012 8:36 PM
    Moderator
  • OK, I'll try that, but is there a way to set that in Visual Studio rather than manually editing it everytime?
    Robert Quattlebaum
    Wednesday, January 18, 2012 8:39 PM
  • Once it's set up you can edit the file as needed inside VS, that's how I do it. Any time I change versions I update the manifest file as well as the AssemblyInfo file. The information in the AssemblyInfo file is updated when you change the properties also.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "vsk9" <=?utf-8?B?dnNrOQ==?=> wrote in message news:cc584f14-a9b3-4827-a145-bed45a2c0b59...
    OK, I'll try that, but is there a way to set that in Visual Studio rather than manually editing it everytime?
    Robert Quattlebaum

    Ken Slovak MVP - Outlook
    Wednesday, January 18, 2012 8:42 PM
    Moderator
  • I've tried this setting and it does not make any difference.
    Robert Quattlebaum
    Thursday, January 19, 2012 3:14 PM
  • Did you check to make sure that no code that's running in Outlook or integrating with Outlook is requesting different permissions than your code? Did you make sure that Outlook was started using the same permissions?
     
    Did you check with all other code that automates Outlook disabled? That would include any addins or synch software that synchs to iPads, iPhones and any other devices. Under those conditions do things work as expected? If so you need to use the process of elimination to see which application or applications are causing a problem.
     
    You can also check to see if the same thing happens on another machine to see if you can get clues from that.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "vsk9" <=?utf-8?B?dnNrOQ==?=> wrote in message news:f591ad23-1100-4cf3-b5d5-b8c328dfce76...
    I've tried this setting and it does not make any difference.
    Robert Quattlebaum

    Ken Slovak MVP - Outlook
    Thursday, January 19, 2012 3:21 PM
    Moderator
  • I'm not sure we're on the same page -- I am not running an instance of Outlook. I'm having the code automatically fire up its own programmatic instance of Outlook. There would not be any other code or add-ins involved at this point, would there? If so, how to check for them?

    When I do fire up a separate instance of Outlook and just have the code reference it, everything works fine. It is only when I programmatically start an instance of Outlook that I have the problem.


    Robert Quattlebaum
    Thursday, January 19, 2012 3:35 PM
  • When you start Outlook using code any addin that runs in Outlook will start up too. It's possible that some startup problems or delays causes by some other code is causing the problem. The only way to absolutely determine that is to disable all addins and then try your code. Additionally, if things work on a different machine then the problem is something on your machine. As with any troubleshooting it's a process of elimination.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "vsk9" <=?utf-8?B?dnNrOQ==?=> wrote in message news:83ed2546-3f94-4d82-b571-134517656649...

    I'm not sure we're on the same page -- I am not running an instance of Outlook. I'm having the code automatically fire up its own programmatic instance of Outlook. There would not be any other code or add-ins involved at this point, would there? If so, how to check for them?

    When I do fire up a separate instance of Outlook and just have the code reference it, everything works fine. It is only when I programmatically start an instance of Outlook that I have the problem.


    Robert Quattlebaum

    Ken Slovak MVP - Outlook
    Thursday, January 19, 2012 3:38 PM
    Moderator
  • Disabled all add-ins one by one, and retried after each was disabled. Still wouldn't run.

    Installed on another computer. Still wouldn't run.

    I'm not sure what else can be eliminated at this point.


    Robert Quattlebaum
    Thursday, January 19, 2012 4:55 PM
  • Unfortunately there are lots of posts like this and almost no solutions listed.
     
    Let's try changing the profile logon used to NameSpace and see if hat helps. Try using GetNameSpace("MAPI") to get an instance of the NameSpace object and supply this as arguments:
     
    Logon("", "", False, False)
     
    See if that helps.
     
    Other things to try before the dreaded workaround of "just start Outlook first" might be to specify the app: mobjOL= New Outlook.Application, or try CreateInstance() to create the Application object.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "vsk9" <=?utf-8?B?dnNrOQ==?=> wrote in message news:2341be7f-2f34-442b-8d49-fe984a3517da...

    Disabled all add-ins one by one, and retried after each was disabled. Still wouldn't run.

    Installed on another computer. Still wouldn't run.

    I'm not sure what else can be eliminated at this point.


    Robert Quattlebaum

    Ken Slovak MVP - Outlook
    Thursday, January 19, 2012 6:23 PM
    Moderator
  • If you will note in the Else clause of my code -- the branch that is executing -- I am already using GetNameSpace("MAPI"). I had also previously tried using Logon("", "", false, false), but that did not work, either.

    Also, in that same branch of code, note that I'm already using mobjOL = new Application (where Application resolves to Outlook.Application). But, just for grins, I tried it explicitly per your note, to no avail.

    I was not able to try CreateInstance, as I cannot get Visual Studio to recognize that command.

    I'm wondering why this is not a very common feature to try, and why there would not be sample code somewhere that shows how to do it.

    I don't know if this is of any significance, but I've noted that every time I make the call to Logon, an instance of Outlook is actually fire up and continues to run until I kill it in Task Manager. It prevents other copies from running until I kill it, yet it seems to be in no condition to respond to calls since I get exceptions thrown in try to access it. I'm going to search for any references to similar code as I am getting nowhere.


    Robert Quattlebaum
    Thursday, January 19, 2012 7:39 PM
  • System.Activator.CreateInstance().
     
    About the only other thing I can think of would be to open a support case with MS and see what comes of that. Of course unless you have MSDN support incidents available or it proves to be an Outlook bug that would cost you.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "vsk9" <=?utf-8?B?dnNrOQ==?=> wrote in message news:52fcd33f-caed-4f45-a924-36050b722cea...

    If you will note in the Else clause of my code -- the branch that is executing -- I am already using GetNameSpace("MAPI"). I had also previously tried using Logon("", "", false, false), but that did not work, either.

    Also, in that same branch of code, note that I'm already using mobjOL = new Application (where Application resolves to Outlook.Application). But, just for grins, I tried it explicitly per your note, to no avail.

    I was not able to try CreateInstance, as I cannot get Visual Studio to recognize that command.

    I'm wondering why this is not a very common feature to try, and why there would not be sample code somewhere that shows how to do it.

    I don't know if this is of any significance, but I've noted that every time I make the call to Logon, an instance of Outlook is actually fire up and continues to run until I kill it in Task Manager. It prevents other copies from running until I kill it, yet it seems to be in no condition to respond to calls since I get exceptions thrown in try to access it. I'm going to search for any references to similar code as I am getting nowhere.


    Robert Quattlebaum

    Ken Slovak MVP - Outlook
    Thursday, January 19, 2012 7:55 PM
    Moderator