anixon Posted January 11, 2010 Share Posted January 11, 2010 In Windows Vista with Outlook running 'outlook.exe' appears as a running process in the 'Windows Task Manager/Process Screen. With 'outlook.exe running if your create an Outlook object '$oOutlook = ObjCreate("Outlook.Application")' you will get a second 'outlook.exe' process running. To release $oOutlook I am currently closing both of the 'outlook.exe' processes using the following code: ;//Closes all Occurances of Outlook $list = ProcessList("Outlook.exe") $s = $list[0][0] For $i = 1 To $list[0][0] ProcessClose($list[$i][1]) Next My question is how do you only close the 'outlook.exe' version created by the object and leave the user launched occurance running. Help is always appreciated. Ant.. Link to comment Share on other sites More sharing options...
water Posted January 11, 2010 Share Posted January 11, 2010 Usually you release an object by setting the variable to 0: $oOutlook = 0 Does this work in your case? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
anixon Posted January 11, 2010 Author Share Posted January 11, 2010 Usually you release an object by setting the variable to 0: $oOutlook = 0 Does this work in your case? Well the short answer is 'No' the 'outlook.exe' created by the object process runs until you perform a process close. Whilst I have not been able to prove the exact cause it may be an issue if in the same script you create an object for Outlook.application for 'Folder' processing as well as a CDO.Message object for sending an Email. Link to comment Share on other sites More sharing options...
ProgAndy Posted January 11, 2010 Share Posted January 11, 2010 Well the short answer is 'No' the 'outlook.exe' created by the object process runs until you perform a process close. Whilst I have not been able to prove the exact cause it may be an issue if in the same script you create an object for Outlook.application for 'Folder' processing as well as a CDO.Message object for sending an Email.The short answer is yes. the object is released, but the application started by the object isn't. You have to call $oObject.quit to do that (just the same as for IE-objetcs). *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
anixon Posted January 11, 2010 Author Share Posted January 11, 2010 (edited) The short answer is yes. the object is released, but the application started by the object isn't. You have to call $oObject.quit to do that (just the same as for IE-objetcs). Thanks for the information which was very much appreciated is it possible to have two Outlook objects running at the same time for example $oOutlook = ObjectCreate(Outlook.Application) and say $oOutlookCDO = ObjectCreate(CDO.Message) and then individually quit them as required using $oOutlook.Quit and/or $oOutlookCDO.Quit Ant.. Edit: $oOutlook.quit "DOES NOT' close the outlook.exe opened when creating the $oOutlook object.... Humm Subject to further testing this code appears to resolve the issues with the Outlook Objects and works with both CDO '[http://schemas.microsoft.com/cdo/configuration/:]' and the Outlook SMTP Account using the $oMessage = $oOutlook.CreateItem($olMailItem) methods. Global $oOutlook, $oOutlookCDO _StopOutlook() _sOutlookObject() _sOutlookObjectCDO() ;//Cleanup Outlook Func _StopOutlook() ;//Close all Occurances of Outlook $list = ProcessList("outlook.exe") $s = $list[0][0] For $i = 1 To $list[0][0] ProcessClose($list[$i][1]) Next EndFunc ;==>_StopStartOutlook ;// Create the Outlook Object Func _sOutlookObject() ;//Create Outlook Object Local $oOutlook = ObjCreate("Outlook.Application") If @error Or Not IsObj($oOutlook) Then Return SetError(1, 0, 0) EndIf Return $oOutlook EndFunc ;==>_sOutlookObject ;// Create the sOutlookObjectCDO Func _sOutlookObjectCDO() ;//Create OutlookCDO Object Local $oOutlookCDO = ObjCreate("CDO.Message") If @error Or Not IsObj($oOutlookCDO) Then Return SetError(1, 0, 0) EndIf Return $oOutlookCDO EndFunc ;==>_sOutlookObjectCDO Edited January 11, 2010 by anixon Link to comment Share on other sites More sharing options...
anixon Posted January 12, 2010 Author Share Posted January 12, 2010 (edited) Thanks for the information which was very much appreciated is it possible to have two Outlook objects running at the same time for example $oOutlook = ObjectCreate(Outlook.Application) and say $oOutlookCDO = ObjectCreate(CDO.Message) and then individually quit them as required using $oOutlook.Quit and/or $oOutlookCDO.Quit Ant.. Edit: $oOutlook.quit "DOES NOT' close the outlook.exe opened when creating the $oOutlook object.... Humm Subject to further testing this code appears to resolve the issues with the Outlook Objects and works with both CDO '[http://schemas.microsoft.com/cdo/configuration/:]' and the Outlook SMTP Account using the $oMessage = $oOutlook.CreateItem($olMailItem) methods. Global $oOutlook, $oOutlookCDO _StopOutlook() _sOutlookObject() _sOutlookObjectCDO() ;//Cleanup Outlook Func _StopOutlook() ;//Close all Occurances of Outlook $list = ProcessList("outlook.exe") $s = $list[0][0] For $i = 1 To $list[0][0] ProcessClose($list[$i][1]) Next EndFunc ;==>_StopStartOutlook ;// Create the Outlook Object Func _sOutlookObject() ;//Create Outlook Object Local $oOutlook = ObjCreate("Outlook.Application") If @error Or Not IsObj($oOutlook) Then Return SetError(1, 0, 0) EndIf Return $oOutlook EndFunc ;==>_sOutlookObject ;// Create the sOutlookObjectCDO Func _sOutlookObjectCDO() ;//Create OutlookCDO Object Local $oOutlookCDO = ObjCreate("CDO.Message") If @error Or Not IsObj($oOutlookCDO) Then Return SetError(1, 0, 0) EndIf Return $oOutlookCDO EndFunc ;==>_sOutlookObjectCDO I am using this code together with the $oOutlookCDO Object. Everything works fine except that each time you send an email with an attachment it also picks up and adds the previously sent attachment so for some reason the the file attached to the message is not being released. I have tried to release the object using setting the $s_attachment variable to "", '$oOutlookCDO = 0 and $sOutlook.quit but none of these resolves this issue. Can anyone help expandcollapse popup;//Email Transport [Send] SMS Receipts, Report Requests and Confirmed Admin Instructions Func _INetSmtpMailComCdo($oOutlookCDO, $s_ToAddress, $s_CcAddress, $s_BccAddress, $s_FromName, $s_FromAddress, $s_Subject, $s_Attachment, _ $s_Body, $iBodyFormat, $iImportance, $s_SmtpServer, $s_IPPort, $s_Username, $s_Password, $s_ssl) $tError = 0 $IsCon = DllCall("WinInet.dll", "int", "InternetGetConnectedState", "int*", 0, "int", 0) If $IsCon[0] <> 0 Then $tError = 0 $iRc = 0 $oOuError = ObjEvent("AutoIt.Error", "_OutlookErrorCDO") $oOutlookCDO.To = $s_ToAddress $oOutlookCDO.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' If $s_CcAddress <> "" Then $oOutlookCDO.Cc = $s_CcAddress If $s_BccAddress <> "" Then $oOutlookCDO.Bcc = $s_BccAddress $oOutlookCDO.Subject = $s_Subject If $s_Attachment <> "" Then FileSetAttrib($s_Attachment, "-RS") $oOutlookCDO.AddAttachment($s_Attachment) EndIf If StringInStr($s_Body, "<") And StringInStr($s_Body, ">") Then $oOutlookCDO.HTMLBody = $s_Body Else $oOutlookCDO.Textbody = $s_Body & @CRLF EndIf $oOutlookCDO.Configuration.Fields.Item("[url="http://schemas.microsoft.com/cdo/configuration/sendusing"]http://schemas.microsoft.com/cdo/configuration/sendusing[/url]") = 2 $oOutlookCDO.Configuration.Fields.Item("[url="http://schemas.microsoft.com/cdo/configuration/smtpserver"]http://schemas.microsoft.com/cdo/configuration/smtpserver[/url]") = $s_SmtpServer $oOutlookCDO.Configuration.Fields.Item("[url="http://schemas.microsoft.com/cdo/configuration/smtpserverport"]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/url]") = $s_IPPort ;//Authenticate SMTP: If $s_Username <> "" Then $oOutlookCDO.Configuration.Fields.Item("[url="http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"]http://schemas.microsoft.com/cdo/configuration/smtpauthenticate[/url]") = 1 $oOutlookCDO.Configuration.Fields.Item("[url="http://schemas.microsoft.com/cdo/configuration/sendusername"]http://schemas.microsoft.com/cdo/configuration/sendusername[/url]") = $s_Username $oOutlookCDO.Configuration.Fields.Item("[url="http://schemas.microsoft.com/cdo/configuration/sendpassword"]http://schemas.microsoft.com/cdo/configuration/sendpassword[/url]") = $s_Password EndIf If $s_ssl <> 0 Then $oOutlookCDO.Configuration.Fields.Item("[url="http://schemas.microsoft.com/cdo/configuration/smtpusessl"]http://schemas.microsoft.com/cdo/configuration/smtpusessl[/url]") = True EndIf ;//Update Settings: $oOutlookCDO.Configuration.Fields.Update ;//Send the Message: $oOutlookCDO.Send $iRc = @error If $iRc = 0 Then Return 1 Else Return SetError(9, 0, 0) EndIf Else ;//Manually Set the Error Trigger for No Internet Connectivity $tError = 1 EndIf ;//Change File Attribute and Release the File Attachment If $s_Attachment <> "" Then FileSetAttrib($s_Attachment, "+RS") EndIf EndFunc ;==>_INetSmtpMailComCdo After further testing the only way that I found that remedied CDO hanging on two attachments was to Delete Outlook and Restart the Object not an eligant solution given that if a user is working in Outlook it simply pulls the rug from under their feet.... A better solution would be appreciated. Ant.. Edited January 12, 2010 by anixon Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now