November, 2008

  • Akash Blogging......

    HOWTO: Set Mailbox Quotas using CDOEXM

    • 4 Comments

    Are you someone who maintains Exchange 2003 servers? Did you ever have a requirement to set the Mailbox quotas for a lot of users at one go?  Here is your solution. The sample code below uses ADSI and Cdoexm to set mailbox quotas for multiple user.

    The following sample is a simple VBScript code sample that sets the StoreQuota, OverQuotaLimit, Hardlimit for a mailbox. To use this sample, paste the following code in a new text file, and then name the file SetMailboxQuota.txt:

    'This script sets the StoreQuota, OverQuotaLimit, Hardlimit for a mailbox.
    
    ' USAGE: cscript SetMailboxQuota.vbs DATAFILE
    ' This code has to be run on a box that has ESM or Exchange 2003 Installed.
    
    Dim obArgs
    Dim cArgs
    
    Set obArgs = WScript.Arguments
    cArgs = obArgs.Count
    
    
    Main
    
    Sub Main()
    Dim FileSysObj
    Dim DataFileName
    Dim DataFile
    Dim sAMAccoutname
    Dim vDistinguishedName
    
    Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
    
    On error Resume Next
    If cArgs <> 1 Then
          WScript.Echo "Usage: cscript SetMailboxQuota.vbs DATAFILE"
          Exit Sub
    End If
    
    Set FileSysObj = CreateObject("Scripting.FileSystemObject")
    
    DataFileName = obArgs.Item(0)
    
    Set DataFile = FileSysObj.OpenTextFile(DataFileName, ForReading, False,0)
    
    Do While Not DataFile.AtEndOfStream
        sAMAccoutname = DataFile.ReadLine
    
        vDistinguishedName = GetDNFromSam(sAMAccoutname)
    
        If vDistinguishedName <> "" then
            WScript.Echo "Sam Account Name:" & sAMAccoutname
            WScript.Echo "Distinguished Name:" & vDistinguishedName
    
            'Please change limits as per your needs
            'The Size Specified is in Kb
            Call SetLimits(vDistinguishedName, 18432,20480,25600)
    
            If Err.Number <> 0 Then
                  sMsg = "Error Setting Limits"
               sMsg = sMsg & Err.Number & " " & Err.Description
               WScript.Echo sMsg
        End If
        else
           WScript.Echo "Could not get Distinguished Name for " & sAMAccoutname
        end if
    
        WScript.Echo 
    Loop
       
    DataFile.Close
    Set DataFile = Nothing
    Set FileSysObj = Nothing
    
    End Sub
    
    Function GetDNFromSam(strsAMAccountName)
    
    Dim iAdCont
    Dim iAdGC 
    Dim Conn 
    Dim Com 
    Dim Rs 
    Dim varGCAdsPath
    Dim strQuery
    
       ' Get the Global Catalog
       Set iAdCont = GetObject("GC:")
      
       For Each iAdGC In iAdCont
          varGCAdsPath = iAdGC.ADsPath
       Next
    
       Set Conn = createobject("ADODB.Connection")
       Set Com = createobject("ADODB.Command")
    
       ' Open the Connection
       Conn.Provider = "ADsDSOObject"
       Conn.Open "ADs Provider"
    
       ' Build the query to find the user based on his Alias
       strQuery = "<" & varGCAdsPath & ">;(sAMAccountName=" & strsAMAccountName & ");mailNickName,distinguishedName;subtree"
    
       Com.ActiveConnection = Conn
       Com.CommandText = strQuery
       Set Rs = Com.Execute
    
       GetDNFromSam = Rs.Fields("distinguishedName")
    
       'Clean Up
       Rs.Close
       Conn.Close
    
       Set Rs = Nothing
       Set Com = Nothing
       Set Conn = Nothing
       Set iAdCont = Nothing
       Set iAdGC = Nothing
    
    End Function
    
    
    Sub SetLimits(strUserDN, vStoreQuota,vOverQuotaLimit,vHardLimit)
    
    Const AD_MODE_READ_WRITE = 3
    Dim strLDAP
    Dim objPerson
    Dim objMailbox
    
        strLDAP = "LDAP://" & strUserDN 
    
        Set objPerson = CreateObject("CDO.Person")
     
        objPerson.DataSource.Open strLDAP,,AD_MODE_READ_WRITE
    
        Set objMailbox = objPerson.GetInterface("IMailboxStore")
    
        'check if the user is mailbox enabled
        If objMailbox.HomeMDB = "" Then
            Wscript.Echo "No Mailbox found."
        Else
           'Give Warning at
            Wscript.Echo "Current StoreQuota:" & objMailbox.StoreQuota
            Wscript.Echo "Setting StoreQuota to:" & vStoreQuota & "(KB)"
            objMailbox.StoreQuota = vStoreQuota
    
           'Prevent Sending at
           Wscript.Echo "Current OverQuotaLimit:" & objMailbox.OverQuotaLimit & "(KB)"
           Wscript.Echo "Setting OverQuotaLimit to:" & vOverQuotaLimit & "(KB)"
           objMailbox.OverQuotaLimit = vOverQuotaLimit
    
           'Prevent Sending and Recieving at
           Wscript.Echo "Current Hardlimit:" & objMailbox.HardLimit & "(KB)"
           Wscript.Echo "Setting StoreQuota to:" & vHardLimit & "(KB)"
           objMailbox.HardLimit = vHardLimit
    
           ' Clearing defaults
           Wscript.Echo "Disabling Database Defaults"
           objMailbox.EnableStoreDefaults = false
           objPerson.DataSource.Save
    
        End If
    
        Set objMailbox = Nothing
        Set objPerson = Nothing
    
    End Sub

    The list of sAMAccountName's can be provided via a text file(Datafile). The Datafile contains the sAMAccountName's of the users(one on each line). So assuming your Datafile is called "sAMAccounts.txt" and is on the C:\, you would run the script as follows:

    C:\>Cscript SetMailboxQuota.vbs C:\sAMAccounts.txt

    The account that you are logged on to the computer must have permissions to change the limits on the mailboxes.

  • Akash Blogging......

    HOWTO: Dump out Contacts using CDOEX and ADO

    • 0 Comments

    The following sample is a simple VBScript code sample that that uses CDOEX and ADO to iterate through multiple mailboxes and dumps out the contact data to a text file. This code must be run on the Exchange server.

    To use this sample, paste the following code in a new text file, and then name the file DumpContacts.vbs:

    'This script must be run on an Exchange Server.
    'USAGE: cscript DumpContacts.vbs DOMAIN Datafile(FullPath)
    
    Dim obArgs
    Dim cArgs
    
    Set obArgs = WScript.Arguments
    cArgs = obArgs.Count
    
    Main
    
    Sub Main()
    Dim FileSysObj
    Dim DataFileName
    Dim DataFile
    Dim alias
    
    Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
    
       If cArgs <> 2 Then
          WScript.Echo "Usage: cscript DumpContacts.vbs DOMAIN Datafile(FullPath)"
          Exit Sub
       End If
    
       Set FileSysObj = CreateObject("Scripting.FileSystemObject")
    
       DataFileName = obArgs.Item(1)
    
       Set DataFile = FileSysObj.OpenTextFile(DataFileName, ForReading, False,0)
    
       'Read line by line to get the mailbox alias from the Datafile
       Do While Not DataFile.AtEndOfStream
         alias = DataFile.ReadLine
    
         'Dump contact data to a csv file
         Call DumpContacts(obArgs.Item(0), alias)
       Loop
       
       DataFile.Close
    
       'Clean up
       Set DataFile = Nothing
       Set FileSysObj = Nothing
    
    End Sub
    
    Sub DumpContacts(Domain, Mailbox)
    
    Dim Rs
    Dim Rec
    Dim strURL
    Dim sMsg
    Dim strLocalPath
    Dim ContactData
    
       On Error Resume Next
    
      ' Specify the URL to a folder or an item.
      strLocalPath = "MBX/" & Mailbox &"/Contacts"
    
      Set Rec = CreateObject("ADODB.Record")
      Set Rs = CreateObject("ADODB.Recordset")
      strURL = "file://./backofficestorage/" & Domain & "/" & strLocalPath
    
      Rec.Open strURL
    
      If Err.Number <> 0 Then
          sMsg = "Error Connecting to the Contact folder for User " & Mailbox & " "
          sMsg = sMsg & Err.Number & " " & Err.Description
          WScript.Echo sMsg
          Exit Sub
      End If
      
      Set Rs.ActiveConnection = Rec.ActiveConnection
    
      Rs.Source = "SELECT ""DAV:href"", " & _
              " ""urn:schemas:contacts:email1"", " & _
                  " ""urn:schemas:contacts:nickname"", " & _
                  " ""urn:schemas:contacts:title"" " & _
                  "FROM scope('shallow traversal of """ & strURL & """') "
      Rs.Open
    
      while Not Rs.EOF
    
        Dim iPerson
        Set iPerson = Createobject("CDO.Person")
        iPerson.DataSource.Open Rs.Fields("DAV:href").Value, Rec.ActiveConnection
    
        ContactData = iPerson.Company & ";"
        ContactData = ContactData & iPerson.Email & ";"
        ContactData = ContactData & iPerson.Email2 & ";"
        ContactData = ContactData & iPerson.Email3 & ";"
        ContactData = ContactData & iPerson.FileAs & ";"
        ContactData = ContactData & iPerson.FileAsMapping & ";"
        ContactData = ContactData & iPerson.FirstName & ";"
        ContactData = ContactData & iPerson.HomeCity & ";"
        ContactData = ContactData & iPerson.HomeCountry & ";"
        ContactData = ContactData & iPerson.HomeFax & ";"
        ContactData = ContactData & iPerson.HomePhone & ";"
        ContactData = ContactData & Replace(iPerson.HomePostalAddress, vbcrlf," ") & ";"
        ContactData = ContactData & iPerson.HomePostalCode & ";"
        ContactData = ContactData & iPerson.HomePostOfficeBox & ";"
        ContactData = ContactData & iPerson.HomeState & ";"
        ContactData = ContactData & iPerson.HomeStreet & ";"
        ContactData = ContactData & iPerson.Initials & ";"
        ContactData = ContactData & iPerson.LastName & ";"
        ContactData = ContactData & Replace(iPerson.MailingAddress, vbcrlf," ") & ";"
        ContactData = ContactData & iPerson.MailingAddressID & ";"
        ContactData = ContactData & iPerson.MiddleName & ";"
        ContactData = ContactData & iPerson.MobilePhone & ";"
        ContactData = ContactData & iPerson.NamePrefix & ";"
        ContactData = ContactData & iPerson.NameSuffix & ";"
        ContactData = ContactData & iPerson.Title & ";"
        ContactData = ContactData & iPerson.WorkCity & ";"
        ContactData = ContactData & iPerson.WorkCountry & ";"
        ContactData = ContactData & iPerson.WorkFax & ";"
        ContactData = ContactData & iPerson.WorkPager & ";"
        ContactData = ContactData & iPerson.WorkPhone & ";"
        ContactData = ContactData & Replace(iPerson.WorkPostalAddress, vbcrlf," ") & ";"
        ContactData = ContactData & iPerson.WorkPostalCode & ";"
        ContactData = ContactData & iPerson.WorkPostOfficeBox & ";"
        ContactData = ContactData & iPerson.WorkState & ";"
        ContactData = ContactData & iPerson.WorkStreet & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:weddinganniversary").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:account").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:bday").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:billinginformation").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:businesshomepage").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:co").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:cn").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:computernetworkname").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:dn").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:gender").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:weddinganniversary").Value & ";"
        ContactData = ContactData & iPerson.Fields("urn:schemas:contacts:manager").Value & ";"
        ContactData = ContactData & iPerson.Fields("http://schemas.microsoft.com/exchange/sensitivity").Value & “;”
    
        WriteFile ContactData 
    
        Rs.MoveNext
    
      wend
      
      Rs.Close
      Rec.Close
    
      'Clean Up  
      Set Rs = Nothing
      Set Rec = Nothing
        
    End Sub
    
    Sub WriteFile(Contents)   
    
    Const ForWriting =2 
    Const ForAppending = 8
    
      Set oFS = CreateObject("Scripting.FileSystemObject") 
      Set oFSFile = oFS.OpenTextFile("C:\Contacts.txt",ForAppending,True) 
    
      oFSFile.WriteLine(Contents) 
      oFSFile.Close 
    
      Set oFSFile = Nothing 
      Set oFS = Nothing 
    
    End Sub 

    The list of mailboxes to scan can be provided via a text file(Datafile). The Datafile contains the aliases of the users(one on each line). So assuming your Datafile is called "Aliases.txt" and is on the C:\, you would run the script as follows:

    C:\>Cscript DumpContacts.vbs "MyDomain.com" "C:\Aliases.txt"

    The account that you are logged on the computer with must have permissions on the mailboxes that you are trying to iterate through. You can give the permissions by following the steps in the article below:

    How to assign service account access to all mailboxes in Exchange Server 2003
    http://support.microsoft.com/kb/821897/

  • Akash Blogging......

    HOW TO:Set folder level permissions using CDO 1.21 and ACL.dll

    • 9 Comments

    This is not something everyone would want to do, but just in case below is the sample code that uses ACL.dll (found in the Platform SDK) to set "Reviewer" permissions on all the folders for a specific user.

    The following sample is a simple VBScript code sample that iterates through all folders in multiple mailboxes and sets the "Reviewer" permissions. To use this sample, paste the following code in a new text file, and then name the file SetFolderPermissions.vbs:

    'This script logs on to a server that is running Exchange Server and iterates through all the mailboxes
    'recursively setting the "Reviewer" permission on each folder for a specific user.
    
    ' USAGE: cscript SetFolderPermissions.vbs SERVERNAME DATAFILE FullUserName
    ' This requires that CDO 1.21 and the Acl.dll is installed on the computer.
    
    Dim obArgs
    Dim cArgs
    Dim objSession
    Dim objInfoStores
    Dim FullUserName
    
    Set obArgs = WScript.Arguments
    cArgs = obArgs.Count
    
    Const CdoMsg = 3,ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
    
    Main
    
    Sub Main()
    Dim FileSysObj
    Dim DataFileName
    Dim DataFile
    Dim alias
    
        If cArgs <> 3 Then
            WScript.Echo "Usage: cscript SetFolderPermissions.vbs SERVERNAME DATAFILE(Name and Path) FullUserName"
            Exit Sub
        End If
    
        Set FileSysObj = CreateObject("Scripting.FileSystemObject")
    
        DataFileName = obArgs.Item(1)
        FullUserName = obArgs.Item(2)
    
    
        Set DataFile = FileSysObj.OpenTextFile(DataFileName, ForReading, False,0)
        
        'Read line by line
        Do While Not DataFile.AtEndOfStream
             alias = DataFile.ReadLine
        
        'Loop through the mailboxes
            Call IterateInfoStores(obArgs.Item(0), alias)
        Loop
       
        DataFile.Close
    
        'Clean Up    
        Set DataFile = Nothing
        Set FileSysObj = Nothing
    
    End Sub
    
    
    Sub IterateInfoStores(ServerName,UserName)
    
    Dim objFolder
    Dim intCounter
    Dim objInfoStore
    Dim sMsg
    
        On Error Resume Next
        
        'Create the new Session Object
        Set objSession = CreateObject("MAPI.Session")
    
        If Err.Number <> 0 Then
          sMsg = "Error creating MAPI.Session."
          sMsg = sMsg & "Make sure CDO 1.21 is installed. "
          sMsg = sMsg & Err.Number & " " & Err.Description
          WScript.Echo sMsg
          Exit Sub
        End If
    
        'Logon to the Mailbox
        objSession.Logon "", "", False, True, 0, False, ServerName & vbLf & UserName
        
        If Err.Number <> 0 Then
          sMsg = "Error logging on: "
          sMsg = sMsg & Err.Number & " " & Err.Description
          WScript.Echo sMsg
          WScript.Echo "Server: " & ServerName
          WScript.Echo "Mailbox: " & UserName
          Set objSession = Nothing
          Exit Sub
        End If
    
        WScript.Echo "Logged On to:" & objSession.CurrentUser
    
        'Loop through the Infostores
        For intCounter = 1 To objSession.InfoStores.Count
            Set objInfoStore = objSession.InfoStores(intCounter)
    
        If Err.Number <> 0 Then
              sMsg = "Error retrieving InfoStore Object: "
              sMsg = sMsg & Err.Number & " " & Err.Description
              WScript.Echo sMsg
              WScript.Echo "Server: " & ServerName
              WScript.Echo "Mailbox: " & UserName
              Set objInfoStore = Nothing
              Set objSession = Nothing
              Exit Sub
        End If
        
            If objInfoStore.Name = "Mailbox - " & objSession.CurrentUser Then
                Exit For
            End If
        Next
        
        Set objFolder = objInfoStore.RootFolder
        
        If Err.Number <> 0 Then
        sMsg = "Error retrieving RootFolder Object: "
        sMsg = sMsg & Err.Number & " " & Err.Description
        WScript.Echo sMsg
        WScript.Echo "Server: " & ServerName
        WScript.Echo "Mailbox: " & UserName
        Set objInfoStore = Nothing
        Set objFolder = Nothing
        Set objSession = Nothing
        Exit Sub
        End If
    
        'Recurse through the sub-folders
        NavigateFolders objFolder
    
        If Err.Number <> 0 Then
        sMsg = "Error: "
        sMsg = sMsg & Err.Number & " " & Err.Description
        WScript.Echo sMsg
        WScript.Echo "Server: " & ServerName
        WScript.Echo "Mailbox: " & UserName
        End If
        
        'Logoff from the session
        objSession.Logoff
    
        'Clean Up
        Set objFolder = Nothing
        Set objInfoStore = Nothing
        Set objSession = Nothing
    End Sub
    
    Sub NavigateFolders(MAPIFolder)
    Dim intCounter
    Dim oDelegate
    Dim oAddrBook
    Dim oNewAce
    Dim ACLObj
    Dim FolderACEs
    Dim objAce
    
    Const ROLE_REVIEWER = &H401
    Const ROLE_OWNER = &H5E3 
    Const ROLE_PUBLISH_EDITOR = &H4E3 
    Const ROLE_EDITOR = &H463 
    Const ROLE_PUBLISH_AUTHOR = &H49B 
    Const ROLE_AUTHOR = &H41B 
    Const ROLE_NONEDITING_AUTHOR = &H413 
    Const ROLE_CONTRIBUTOR = &H402 
    Const ROLE_NONE = &H400 
    
    
        WScript.Echo "Folder Name:" & MAPIFolder.Name
    
        'Create the ACL object
        Set ACLObj = CreateObject("MSExchange.aclobject")
        
        ' Associate the ACLObject to the CDO Folder
        ACLObj.CDOItem = MAPIFolder
        Set FolderACEs = ACLObj.ACEs
    
        ' Create a MAPI object for UserA
        Set oAddrBook = objSession.AddressLists("Global Address List")
    
        Set oDelegate = oAddrBook.AddressEntries.Item(FullUserName)
    
        Set oNewAce = CreateObject("MSExchange.ACE")
    
        oNewAce.ID = oDelegate.ID
        oNewAce.Rights = ROLE_REVIEWER
        FolderACEs.Add oNewAce
        ACLObj.Update
    
        ' Loop through all of the ACEs for the folder and display them
        For each objAce in  FolderACEs
        WScript.Echo GetACLEntryName(objAce.ID) & " - " & DispACERules(objAce)
        Next
        WScript.Echo ""
    
        ' Clean up objects
        Set objAce = Nothing
        Set oNewAce = Nothing
        Set FolderACEs = Nothing
        Set ACLObj = Nothing
    
        If MAPIFolder.Folders.Count > 0 Then
            For intCounter = 1 To MAPIFolder.Folders.Count
                NavigateFolders MAPIFolder.Folders(intCounter)
            Next
        End If
    
    
    End Sub
    
    Function GetACLEntryName(ACLEntryID)
    On Error resume Next
    ' This function finds the user that is listed as an ACE on the folder.
    ' It takes the ID that it is passed and uses the Session.GetAddressEntry method
    ' to find the name.
        
        Dim tmpEntry
        Dim tmpName
    
        Select Case ACLEntryID
        Case "ID_ACL_DEFAULT"
                GetACLEntryName = "Default"
        Case "ID_ACL_ANONYMOUS"
                GetACLEntryName = "Anonymous"
        Case else
           ' Get the name of the ACE
            Set tmpEntry = objSession.GetAddressEntry(ACLEntryID)
                tmpName = tmpEntry.Name
                GetACLEntryName = tmpName
        End Select
        
    End Function
    
    Function DispACERules(DisptmpACE)
    ' This function checks the roles of the ACE that is passed to it and    returns
    ' the Role back.
    Const ROLE_NONE = 1024
    Const ROLE_AUTHOR = 1051
    Const ROLE_CONTRIBUTOR = 1026
    Const ROLE_PUBLISH_AUTHOR = 1179
    Const ROLE_NONEDITING_AUTHOR = 1043
    Const ROLE_REVIEWER = 1025
    Const ROLE_EDITOR = 1147
    Const ROLE_OWNER = 2043
    Const ROLE_PUBLISH_EDITOR = 1275  
    
        ' Check the roles on the folder
        Select Case DisptmpACE.Rights
            Case ROLE_NONE, 0  ' Checking in case the role has not been set on that entry.
                    DispACERules = "None"
            Case ROLE_AUTHOR
                    DispACERules = "Author"
            Case ROLE_CONTRIBUTOR
                    DispACERules = "Contributor"
            Case ROLE_EDITOR
                    DispACERules = "Editor"
            Case ROLE_NONEDITING_AUTHOR
                    DispACERules = "Nonediting Author"
            Case ROLE_OWNER
                    DispACERules = "Owner"
            Case ROLE_PUBLISH_AUTHOR
                    DispACERules = "Publishing Author"
            Case ROLE_PUBLISH_EDITOR
                    DispACERules = "Publishing Editor"
            Case ROLE_REVIEWER
                    DispACERules = "Reviewer"
            Case Else
            ' This will grab all other custom permissions on the folder
                    DispACERules = "Custom"
        End Select
    
    End Function
     

    The list of mailboxes can be provided via a text file(Datafile). The Datafile contains the aliases of the users(one on each line). So assuming your Datafile is called "Aliases.txt" and is on the C:\, you would run the script as follows:

    C:\>Cscript SetFolderPermissions.vbs Exchange2003 C:\Aliases.txt "Akash Bhargava"

    The script currently sets and also dumps out the permissions on each folder in the mailbox.

    The account that you are logged on the computer with must have permissions on the mailboxes that you are trying to iterate through. You can give the permissions by following the steps in the article below:

    How to assign service account access to all mailboxes in Exchange Server 2003
    http://support.microsoft.com/kb/821897/

    Enjoy!

  • Akash Blogging......

    Unable to Instantiate Outlook Object from Visual Studio 2008 on Vista with UAC ON?

    • 3 Comments

    Having problems in instantiating a new Outlook object from VS 2008(Windows Form Application) when running on Vista with UAC ON? Getting weird errors similar to the ones below?

    System.Runtime.InteropServices.COMException was unhandled
      Message="Creating an instance of the COM component with CLSID {0006F03A-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80010001."
      Source="MyApp"
      ErrorCode=-2147418111

    This error was when Outlook was NOT running and I tried to debug my application from Visual studio 2008.

    System.Runtime.InteropServices.COMException was unhandled
      Message="Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005."
      Source="MyApp"
      ErrorCode=-2146959355

    This error was when Outlook was already running and I tried to debug my application from Visual studio 2008. In both cases I got the error when I tried to instantiate a new object of the Outlook.Application.

    oApp = new Outlook.Application

    Using the Err.exe to get more details on the 80010001 and the 80080005 we get the following details:

    # for hex 0x80010001 / decimal -2147418111 :
      DBG_EXCEPTION_NOT_HANDLED                                     ntstatus.h    
    # Debugger did not handle the exception.
      RPC_E_CALL_REJECTED                                           winerror.h    
    # Call was rejected by callee.
    # 2 matches found for "80010001"

    # for hex 0x80080005 / decimal -2146959355 :
      CO_E_SERVER_EXEC_FAILURE                                      winerror.h    
    # Server execution failed
    # 1 matches found for "80080005"

    Why would we be getting a RPC_E_CALL_REJECTED or CO_E_SERVER_EXEC_FAILURE? In my case this was happening because of the difference in Integrity Level of the two processes(Outlook.exe and devenv.exe)

    The Visual Studio 2008 was being "Run as administrator" which makes it run in High IL and Outlook was by default running in Medium IL and this was causing the errors. The solution is run both the processes in the same IL.

    How can you check the Integrity Level of a process? Use Process Explorer(Click on the View menu -> Select Columns->Process Image Tab and check Integrity Level)

    Hope this helps!

Page 1 of 1 (4 items)