Sign in to follow this  
Followers 0
anixon

Objects

6 posts in this topic

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..

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by anixon

Share this post


Link to post
Share on other sites

#6 ·  Posted (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

;//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 by anixon

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0