Hello Armstrong......you asked the following:
1. Why ShutDownWindows>2, instead of ShutDownWindows>0, is used?
I want to Log Off at the workstation, not to Shut Down. This unit has shared resources to be used by others, and must stay on line.
2. If Msched.exe is killed, how could we logically expect ShutDownWindows remains functional?
Excellent question!
It does do it under some circumstances. and I think this is a clue to to the error.
I apologize for the length of the following, but think it will be useful.
===========================
Original environment of problem was to have MS running in the systray. Clicking on a shortcut icon to run a macro to Log Off using ShutDownWindows>2. Clicking on that icon at times was causing a Access Conflict error. But I found that the error did not always happen.
Using KILL and TLIST utilities (Thank you very much!

), I created the following script to remove any copies of MS already running before executing ShutDownWindows>2 command.
The script redirects the output of TLIST to a file. FIND is then used to find lines of MS to get the PID for use with KILL. KILL is then executed and the routine loops until no more copies of MS are found. Then it goes to ShutDownWindows. (There is also a quick test option at the top to just repeatedly try to log off as test conditions are changed).
Following this script are some notes about using the script and my observations and conclusions.
=========================
Label>Purpose of MSKILL script
//This is to avoid the error message that occurs when selecting a
//shortcut icon to ShutDownWindows>. If Macro Scheduler (MS)is already
//running in the system tray, a conflict error message sometimes comes up
//Need to use KILL.EXE to close earlier running copies of MS (PID changes every time)
Label>Skip
//Activate next line to skip Kill routine and try to Log Off immediately
//GoTo>Close
Label>Start
Let>RP_WINDOWMODE=0
Let>Killed=0
//NoKill is size of empty kill.txt file
Let>NoKill=24
Add>NoKill,1
Change Directory>C:\temp
Label>Kill
//Start Kill Loop
DeleteFile>alive.txt
DeleteFile>kill.txt
//Redirect tlist output to file
Run Program>command.com /c c:\windows\command\tlist.exe > alive.txt
Wait>2
//Read line that has Macro Scheduler
Run Program>command.com /c c:\windows\command\find.exe "Macro Scheduler" alive.txt>kill.txt
Wait>5
//Macro Scheduler is closed if killsize=nokill, process is done
FileSize>kill.txt,killsize
If>%killsize%kill.txt,3,killme
Pos>MS,%killme%,1,PIDend
Sub>PIDend,1
MidStr>%killme%,1,%PIDend%,PID
//Run KILL /f for that PID
Run Program>command.com /c c:\windows\command\kill.exe /f %PID%
Wait>2
Add>Killed,1
Message>Just killed a copy of MS.%CRLF%%CRLF%Killed %Killed% so far.
Wait>5
//End Kill Loop
//Check for more MS running copies
Goto>Kill
Label>Dead
Message>Other copies of MS are not loaded%CRLF%%CRLF%Total of %Killed% were closed.
Wait>10
Label>Continue to ShutDownWindows>
Label>Close
ShutDownWindows>2
===============================
Steps to reproduce tools analysis:
1. Make a desktop shortcut for this MSKILL script
2. Close all copies of MS
3. Open 1 copy of MS to see icon in systray
4. Open a Command Window and run tlist.exe to see 1 copy of MS with title of Macro Scheduler.
5. Double click on desktop icon to remove already running MS copies
6. Note another copy is shown in systray, ond flashing.
7. When done, see message that a total of 1 copy was closed (that was the original). See one icon in systray, not blinking. Message will go away.
8. In the Command Window run tlist.exe to see 1 copies.of MSCHED with title of "OleMainThreadWndName".
9. After a few moments final MS icons will go away from systray.
10 In the Command Window run tlist.exe to see 0 copies.of MSCHED
Repeat steps 2-10 above, but open 3 copies of MS in step 3 vs. 1 copy. Step 4 will show 3 copies. Three messages will come up as each copy is killed. Icons are not removed in systray until entire process has been completed.
======== COMMENTS ===========
The fact that the final message came up after KILLing MS would seem to indicate that the running script is in a memory location separate from the main MS program. It continues to process somehow even though MS has been removed?
If close all copies of MS (vs. having one copy running) and run from icon, then macro does not complete which means that at least one copy of MS must be running to do ShutDownWindows>2.
TLIST provides a method to see "title" about the running tasks.
If no MS copies are already running, do get error message with SDW>2.
If one copy is runnning get no error message, unless "Macro Scheduler" has changed to "OleMainThreadWndName". What makes that change names? There also seems to be no external indication of the "title" change.
It looks like if MS is already running the second copy is given the name "OleMainThreadWndName".
If MS is running = get error
If MS not running = no error
If MS running, KillMS Script = no error
OleMainThreadWndName, Kill Script = error
Doing various activitiies with one copy of MS in systray, and runnning TLIST. I have been able to make the title change from "Macro Scheduler" to "OleMainThreadWndName", but haven't figured out the logic yet. I'm getting an area that I am not familiar with and hope that Marcus can use this to help solve the problem.
My conclusion at this point:
Error problem is not consistent, but it only seems to happen if there is no MS running with the title "Macro Scheduler", but a copy running with the title "OleMainThreadWndName".
Thanks for all the help so far.