HighlanderSword Posted March 27, 2020 Posted March 27, 2020 (edited) Hello, When i use the below codea nd run it manually as the compiled exe it works fine ( Sends as the user I specify) When I use Task Schedule to schedule the task to run (set up to run with Highest Privs , tried only run when user is logged on , as well as run whether user is logged on or not), I get an error variable must be of an object type, it appears to get hung up using the send as account Any ideas how to get this to work #include <OutlookEX.au3> Global $oItem Global $oOutlook = _OL_Open() _OL_ErrorNotify(2) $oItem = _OL_ItemCreate($oOutlook, $olMailItem, "", "", "Subject=TestMail", "Body=TestBody") If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemCreate Example Script", "Error creating mail. @error = " & @error & ", @extended = " & @extended) $oItem = _OL_ItemRecipientAdd($oOutlook, $oItem, Default, $olTo, "test@test.com") ; Recipient For $oAccount In $oOutlook.Session.Accounts If $oAccount.SMTPAddress = "smtp to use" Then ; SMTP address of the desired sender $oItem.SendUsingAccount = $oaccount ExitLoop EndIf Next _OL_ItemSend($oOutlook, $oItem) _OL_Close($oOutlook) Edited March 27, 2020 by HighlanderSword updates
water Posted March 27, 2020 Posted March 27, 2020 Could you please add some error checking for ALL calls to an _OL* function? Does _OL_Open set @error? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
HighlanderSword Posted March 27, 2020 Author Posted March 27, 2020 Added error checking used _FileWriteLog 2020-03-27 03:48:55 : OL_OPen error status 1 - -2147221164 2020-03-27 03:48:55 : OL_Erronotify 0 - 0 2020-03-27 03:48:55 : OL_Itemcreate 1 - 3 2020-03-27 03:48:55 : OL_ItemRecipientAdd 2 - 1 2020-03-27 03:48:55 : OL_ItemSend 1 - 1 2020-03-27 03:48:55 : OL_Close 1 - 1 expandcollapse popup#include <OutlookEX.au3> Global $oItem Global $oOutlook = _OL_Open() $Strerror= @error $Strmsg = "OL_OPen error status " & $Strerror & " - " & @extended _FileWriteLog("D:\log.txt",$Strmsg) ;~ MsgBox(0,"error status",@error & " - " & @extended) ;~ _OL_ErrorNotify(2) $Strerror= @error $Strmsg = "OL_Erronotify " & $Strerror & " - " & @extended _FileWriteLog("D:\log.txt",$Strmsg) $oItem = _OL_ItemCreate($oOutlook, $olMailItem, "", "", "Subject=TestMail", "Body=TestBody") $Strerror= @error $Strmsg = "OL_Itemcreate " & $Strerror & " - " & @extended _FileWriteLog("D:\log.txt",$Strmsg) $oItem = _OL_ItemRecipientAdd($oOutlook, $oItem, Default, $olTo, "xxx@xxxxx.com") ; Recipient $Strerror= @error $Strmsg = "OL_ItemRecipientAdd " & $Strerror & " - " & @extended _FileWriteLog("D:\log.txt",$Strmsg) For $oAccount In $oOutlook.Session.Accounts If $oAccount.SMTPAddress = "rrrrrr@rrrrrrr.com" Then ; SMTP address of the desired sender $oItem.SendUsingAccount = $oaccount ExitLoop EndIf Next _OL_ItemSend($oOutlook, $oItem) $Strerror= @error $Strmsg = "OL_ItemSend " & $Strerror & " - " & @extended _FileWriteLog("D:\log.txt",$Strmsg) _OL_Close($oOutlook) $Strerror= @error $Strmsg = "OL_Close " & $Strerror & " - " & @extended _FileWriteLog("D:\log.txt",$Strmsg)
water Posted March 27, 2020 Posted March 27, 2020 28 minutes ago, HighlanderSword said: -2147221164 This is the decimal value for the hex hresult 0x80040154: This stands vor REGDB_E_CLASSNOTREG and means that Outlook is not installed for the user running the script. Which account did you set to run your script? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted March 27, 2020 Posted March 27, 2020 Is Outlook running (means: started by you as a user) when the scheduled task runs? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted March 27, 2020 Posted March 27, 2020 Can you please stop Outlook and then start the task again? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
HighlanderSword Posted March 27, 2020 Author Posted March 27, 2020 Stopped outlook and ran scheduled task and it worked. Anyway to have it work while outlook is already open ?
water Posted March 27, 2020 Posted March 27, 2020 This behavior is described in the wiki Quote It seems that the process that starts or hooks into Outlook needs to be run with the same permissions as Outlook. I assume you are connected to an AD domain. Can you please specify the user to run the task as Domainname\Username? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
HighlanderSword Posted March 27, 2020 Author Posted March 27, 2020 (edited) not in and AD Domain , just a stand alone computer at home Edited March 27, 2020 by HighlanderSword
water Posted March 27, 2020 Posted March 27, 2020 It seems the logged in user and the user to run the task are somehow different. As I work in an AD environment I'm very familiar with local accounts. You could run a script via task scheduler that writes the user and domain related information to a file. Means all the Macros like @LogonDNSDomainLogon, @LogonDomainLogon, @LogonServer, @UserName. Then run the script as logged on user and compare this results. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
HighlanderSword Posted March 28, 2020 Author Posted March 28, 2020 OK, I deleted the scheduled Task and re-created it and now it it working Thanks for your help.
water Posted March 28, 2020 Posted March 28, 2020 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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