Jump to content

ProcessWait


Recommended Posts

This code opens Outlook but the script does not pause whilst the default email client is running [Vista]

CODE
While 1

If $mprocess = 1 Then ;Email Processing

$EmailInput = GUICtrlRead($EmailAddr)

$ApplicInput = GUICtrlRead($ApplicNo)

GUIDelete()

$Address = $EmailInput

$Subject = "sSentry Licence Application Number: " & $ApplicInput

$Body = "The Licence Key for your installation of sSentry is: " & $LKeyDisplay

ProcessWait(_INetMail($Address, $Subject, $Body))

If @error = 1 Then

MessageAndLog("Email Client NOT FOUND",200)

EndIf

EndIf

ExitLoop

WEnd

Assistance is always appreciated Ant..

Link to comment
Share on other sites

  • Moderators

ProcessWait pauses until the process exists.

ProcessWaitClose pauses until the process does not exist

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

ProcessWait pauses until the process exists.

ProcessWaitClose pauses until the process does not exist

Ok tried that but both ProcessWait and ProcessWaitClose have no effect. What I am expecting is the scripts window to close based on the GUIDelete() statement within the code and not get repainted until the Email client closes and the input screen gets repainted because the code email processing code is wrapped by another While 1 ....WEnd Statement which manages the user Input Screen.

While 1

;Paints a screen

;Coded for User Input

;Select based on Case [Exit, Save, View, Email]

;Process the Case and Exit the Loop [user Input and Process selection]

;EndSelect

While 1

Do the email thing\

Exit the loop

WEnd

WEnd

This does not work either

$PID = _INetMail($Address, $Subject, $Body)

ProcessWaitClose($PID)

Happy to post the code if that is helpful

Ant..

Edited by anixon
Link to comment
Share on other sites

This is the only way I could get it the script to wait whilst an email was being processed:

CODE
#include <INet.au3> ;Email Processor

$Address = "anyone@anywhere.com"

$Subject = "Application Number: "

$Body = "The detail is as follows: "

$PID = (_INetMail($Address, $Subject, $Body))

While 1

If Not ProcessExists($PID) then

ExitLoop

EndIf

Sleep(1000)

WEnd

msgbox(0,"","I waited like the good script I am")

Exit

Link to comment
Share on other sites

This is the only way I could get it the script to wait whilst an email was being processed:

Well, using your above post as a framework with ProcessWaitClose(), this definitely works for me:

#include <INet.au3>;Email Processor

$Address = "anyone@anywhere.com"
$Subject = "Application Number: "
$Body = "The detail is as follows: "
$PID = (_INetMail($Address, $Subject, $Body))

ProcessWaitClose($Pid)
msgbox(0,"","I waited like the good script I am")

Exit

What problem are you having; not getting the msgbox or the msgbox popping up before the email program is closed?

Link to comment
Share on other sites

Well, using your above post as a framework with ProcessWaitClose(), this definitely works for me:

#include <INet.au3>;Email Processor

$Address = "anyone@anywhere.com"
$Subject = "Application Number: "
$Body = "The detail is as follows: "
$PID = (_INetMail($Address, $Subject, $Body))

ProcessWaitClose($Pid)
msgbox(0,"","I waited like the good script I am")

Exit

What problem are you having; not getting the msgbox or the msgbox popping up before the email program is closed?

Correct the msgbox is popping up before the email program is closed. Is it a Vista specific issue? Ant..
Link to comment
Share on other sites

  • Moderators

Correct the msgbox is popping up before the email program is closed. Is it a Vista specific issue? Ant..

There may be more than 1 executable running and you're only capturing the main one, maybe it does a shutdown sequence with other ones.

Try this in the message box after ProcessClose():

etc...
$PID = _INetMail($Address, $Subject, $Body)

ProcessWaitClose($Pid)
MsgBox(64, "Info", "Process has been closed and does not exist = " & (ProcessExists($PID) = 0))
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

There may be more than 1 executable running and you're only capturing the main one, maybe it does a shutdown sequence with other ones.

Try this in the message box after ProcessClose():

etc...
$PID = _INetMail($Address, $Subject, $Body)

ProcessWaitClose($Pid)
MsgBox(64, "Info", "Process has been closed and does not exist = " & (ProcessExists($PID) = 0))

With your code the Msgbox still opens whilst the Email Client is running and the ProcessExists($PID) variable produces the answer = "True". However effectlvely ProcessWaitClose has no effect. Is it getting the right PID? The only way I could get it to work was the ProcessExists statement using a loop as previously posted for this item. Its a mystery..... Ant..

Edit..

I also tried it compiled with no other AutoIT Process running made no difference. Ant..

Edited by anixon
Link to comment
Share on other sites

I compiled this code and ran it in both Windows XP SP3 and Vista SP1

$Address = "anyone@anywhere.com"

$Subject = "Application Number: "

$Body = "The detail is as follows: "

$PID = _INetMail($Address, $Subject, $Body)

ProcessWaitClose($Pid)

MsgBox(64, "Info", "Process has been closed and does not exist = " & (ProcessExists($PID) = 0))

Exit

The ProcessWaitClose works - waits for Email Client to close before displaying the Msgbox in Windows XP SP3 but displays the Msgbox whilst the Email Client is running in Windows Vista. On the basis of this testing it would be easy to conclude that it was a bug applicable to Vista.. Ant..

Link to comment
Share on other sites

  • Moderators

I compiled this code and ran it in both Windows XP SP3 and Vista SP1

$Address = "anyone@anywhere.com"

$Subject = "Application Number: "

$Body = "The detail is as follows: "

$PID = _INetMail($Address, $Subject, $Body)

ProcessWaitClose($Pid)

MsgBox(64, "Info", "Process has been closed and does not exist = " & (ProcessExists($PID) = 0))

Exit

The ProcessWaitClose works - waits for Email Client to close before displaying the Msgbox in Windows XP SP3 but displays the Msgbox whilst the Email Client is running in Windows Vista. On the basis of this testing it would be easy to conclude that it was a bug applicable to Vista.. Ant..

I'd suggest you create a working example and post it in the bug trac then... and use your work around until then. It very well may be an issue with vista. I'm not quite sure how they wrote ProcessWaitClose()... however I'm sure they use http://msdn.microsoft.com/en-us/library/ms687032.aspx for ProcessWait() which supports vista as well.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I'd suggest you create a working example and post it in the bug trac then... and use your work around until then. It very well may be an issue with vista. I'm not quite sure how they wrote ProcessWaitClose()... however I'm sure they use http://msdn.microsoft.com/en-us/library/ms687032.aspx for ProcessWait() which supports vista as well.

It is not my practice to switch off my Desktop during any 24 hour cycle. That being the case I have just done a COLD BOOT on my Vista Desktop and run both versions of the process 'ProcessWaitClose" and the "ProcessExists" and now they both work. I guess that the COLD BOOT has released some process which was not obvious. In such circumstances and not being able to clearly identify what was the point of failure is there any point in posting a bug report? Ant..

Link to comment
Share on other sites

  • Moderators

It is not my practice to switch off my Desktop during any 24 hour cycle. That being the case I have just done a COLD BOOT on my Vista Desktop and run both versions of the process 'ProcessWaitClose" and the "ProcessExists" and now they both work. I guess that the COLD BOOT has released some process which was not obvious. In such circumstances and not being able to clearly identify what was the point of failure is there any point in posting a bug report? Ant..

No, it was obviously a PC issue and not a code issue.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

No, it was obviously a PC issue and not a code issue.

Then in the words of General Douglas MacArthur who on the Battleship Missouri in Tokyo Bay at 9:25am on the 2nd September 1945 said these words These proceedings are now closed Ant..

Link to comment
Share on other sites

Given that MacArthur has left this mortal coil [long time ago] he was not really in a position to declare these proceedings closed....

For information I have lodged this bug report item #389 as follows:

Quote:

The following process fails to stop script execution when Outlook has previously been opened and closed by a user in Windows Vista.

#include <INet.au3>;Email Processor

$Address = "anyone@anywhere.com"

$Subject = "Application Number: "

$Body = "The detail is as follows: "

$PID = (_INetMail($Address, $Subject, $Body))

ProcessWaitClose($Pid)

msgbox(0,"","I waited like the good script I am")

Exit

The reason for this is that oulook.exe is still listed as a running process as reported by "Task Manager - Processes".

If you 'End Process" outlook.exe in Task Manager - Processes then when running the "ProcessWaitClose' script it pauses execution whilst Outlook.exe has been launched by _INetMail.

To remedy this perhaps registry should be read HKCR\mailto\shell\open\command\"default value" to determine the name of the default executable [outlook.exe or msmn.exe] Email client and close any running processes.

My guess is that the Windows mail client continues to run to manage desktop delivery processing

UnQuote:

Perhaps all that is needed is some code to extract the default client executable from the Data string located in registry item HKCR\mailto\shell\open\command\[default] - Type REG_SZ - Data = PROGRA~1\MICROS~2\OFFICE11\OUTLOOK.EXE -c IPM.Note /m "%1" and close the PID before opening the Mail Client using the _INetMail

Edit:

What I forgot to mention is if the script opens Outlook using _INetMail and you then close Outlook normally then Outlook is not left as a running process.

Comments would be appreciated.

Edited by anixon
Link to comment
Share on other sites

  • Moderators

Given that MacArthur has left this mortal coil [long time ago] he was not really in a position to declare these proceedings closed....

For information I have lodged this bug report item #389 as follows:

Quote:

The following process fails to stop script execution when Outlook has previously been opened and closed by a user in Windows Vista.

#include <INet.au3>;Email Processor

$Address = "anyone@anywhere.com"

$Subject = "Application Number: "

$Body = "The detail is as follows: "

$PID = (_INetMail($Address, $Subject, $Body))

ProcessWaitClose($Pid)

msgbox(0,"","I waited like the good script I am")

Exit

The reason for this is that oulook.exe is still listed as a running process as reported by "Task Manager - Processes".

If you 'End Process" outlook.exe in Task Manager - Processes then when running the "ProcessWaitClose' script it pauses execution whilst Outlook.exe has been launched by _INetMail.

To remedy this perhaps registry should be read HKCR\mailto\shell\open\command\"default value" to determine the name of the default executable [outlook.exe or msmn.exe] Email client and close any running processes.

My guess is that the Windows mail client continues to run to manage desktop delivery processing

UnQuote:

Perhaps all that is needed is some code to extract the default client executable from the Data string located in registry item HKCR\mailto\shell\open\command\[default] - Type REG_SZ - Data = PROGRA~1\MICROS~2\OFFICE11\OUTLOOK.EXE -c IPM.Note /m "%1" and close the PID before opening the Mail Client using the _INetMail

Edit:

What I forgot to mention is if the script opens Outlook using _INetMail and you then close Outlook normally then Outlook is not left as a running process.

Comments would be appreciated.

That's nothing that should be built in, that's something the end-user/scripter should be checking (error handling :) ).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Perhaps all that is needed is some code to extract the default client executable from the Data string located in registry item HKCR\mailto\shell\open\command\[default] - Type REG_SZ - Data = PROGRA~1\MICROS~2\OFFICE11\OUTLOOK.EXE -c IPM.Note /m "%1" and close the PID before opening the Mail Client using the _INetMail

Comments would be appreciated.

Hmmm, I'm not sure that a command that is meant to launch something should go about closing things (without consent) ahead of time. It sounds more like you should be writing your own _INetMailEx() function that would do the registry checking and ProcessClose you're talking about and then pass the parameters to the regular _INetMail() function.

Or maybe you should be checking for the closing of the particular new message window you create and leave the process alone?

Or maybe use one of the command line mailing programs, like BLAT?

Edit: Yeah, what SmOke said...

Edited by ResNullius
Link to comment
Share on other sites

That's nothing that should be built in, that's something the end-user/scripter should be checking (error handling :) ).

You are probably right so I guess the pause only works where outlook is not running as a pre-existing process in which case if the process is pre-existing for the pause to work that process would have to be closed. I'm comfortable with that so is the registry address the correct location for the default Email Client? and secondly what would be the best way of extracting the exact name of the executable from that data [outlook.exe] so that you could then test for a PID? aNT..
Link to comment
Share on other sites

  • Moderators

You are probably right so I guess the pause only works where outlook is not running as a pre-existing process in which case if the process is pre-existing for the pause to work that process would have to be closed. I'm comfortable with that so is the registry address the correct location for the default Email Client? and secondly what would be the best way of extracting the exact name of the executable from that data [outlook.exe] so that you could then test for a PID? aNT..

HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail

Should be pretty self explanatory.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Microsoft describes a problem with Outlook continuing to run after being closed as follows:

The Outlook window closes, but the application continues to run when you try to exit Outlook

The solution is described in the following support item http://support.microsoft.com/kb/914909

which is basically a process of identifying by elimination the Add-Ins listed in the Add-In Manager and/or COM Add-Ins that are not allowing Outlook to close properly and release the PID.

The issue extensively documented in this forum topic clearly is not an AutoIT functionality issue but it might we worth while for an AutoIT scripter to consider code to close the PID process that was not closed due to an Add-on issue to cover a situation where Outlook has not closed properly and the problem is not known to the end user.

Ant..

QED.

Link to comment
Share on other sites

For those who have been following this forum item this is a solution:

CODE
$Address = "anyone@anywhere.com"

$Subject = "Application Number: "

$Body = "The detail is as follows: "

_INetMail($Address, $Subject, $Body) ;your handy work

WinWait($Subject) ;Pauses the script to allow the Windows process mailto: to become active

WinWaitClose(WinGetTitle("Application"),"",60) ;Pauses the script for 60 seconds whilst the email window created by the _INetMail process remains open

msgbox(0,"","I waited like the good script I am"); gratuitous remarks as proof that it works

Exit

Special thanks to all those who participated with good advice in particular Wolvereness [Author of _INetMail] who was more than helpful and pointed me towards

a solution that would work given my circumstances [previous outlook.exe process not properly closed].

Ant.. :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...