Jump to content
Macro Express Forums

Help Sought With Wait Program Terminate Issue.


alainsane

Recommended Posts

Greetings,

 

I've been using ME for about a year now--and have been using it in increasingly advanced ways. Recently, I created a macro that processes through a text file containing MAC Addresses and IP Addresses.

 

For each line of the text file, the macro parses the MAC Address portion into one variable and the IP Address into another variable. A ping is done on the IP Address. If the ping results come back with no response, a wake-on-lan is sent to the corresponding MAC address, the sleepy PC information is written to a different text file and the next line is processed.

 

If the IP gets a ping response, it copies files to the corresponding PC using the Admin (C$) share using Xcopy.exe. It's supposed to wait for xcopy.exe to close (wait indefinitely) before running a netsvc.exe command (designed to remotely start a service). The macro is then supposed to wait for that program to close, too, (also indefinitely) before going back to process the next line of the file.

 

MacroExpress processes the file perfectly most of the time. In about 5% of the cases, however, it will not wait for the xcopy.exe program to terminate or it will not wait for the netsvc.exe program to terminate or both. I am only eyeballing the programs' DOS windows on the screen to make this assessment. The windows are still visible on the screen and will hang there for a quite a while after. Eventually, they close of their own volition, but the processing of the text file has long since resumed.

 

It's crucial to the success of the macro that the netsvc.exe *not* run until the xcopy.exe command has completed executing and closed because the netsvc.exe launches a service the executable of which is being copied over via the xcopy.exe. No executable copied: no service actually launched. In fact, it's more harmful than that because the service is started but then gets stuck because it couldn't launch its executable.

 

This is not the only instance of ME not being bulletproof I have ever seen, but this seems pretty simple stuff. Does anyone have any ideas about what might be going on with ME? Is this just an acceptable loss for a program like this?

 

Thanks for reading. :)

 

k4ayo3.jpg

Link to comment
Share on other sites

Perhaps you could try the Wait for Window Title to Lose Focus command instead of Wait for Program to Terminate. I'm guessing Macex may occasionally miss those Dos-based programs.

 

Alternatively, you could scrap the Wait for... commands, and just insert a really long delay (2 x the maximum time required between the operations). As a fail-safe, you could add code to look for any still-running program, and either terminate the macro or delay for a while more.

 

-Lemming

Link to comment
Share on other sites

Yo might want to try something like this. It checks to see if the process is still running and, if it is, continues to wait. Note, however, that if more than one xcopy.exe is running, this will wait until both of them are finished.

 

Repeat with Processes: Place process in %T1%
 If Variable %T1% contains "xcopy.exe"
   Delay 10 Seconds
 Else
   Break
 End If
Repeat End

Disclaimers: This is untested. If Windows does not add xcopy.exe to the list of running processes then this macro will not work. But, even if it doesn't work, it might give you some ideas about how to do what you need.

Link to comment
Share on other sites

If the IP gets a ping response, it copies files to the corresponding PC using the Admin (C$) share using Xcopy.exe. It's supposed to wait for xcopy.exe to close (wait indefinitely) before running a netsvc.exe command (designed to remotely start a service). The macro is then supposed to wait for that program to close, too, (also indefinitely) before going back to process the next line of the file.

If you're copying files over the network from one machine to another, I very strongly recommend you use Robocopy instead of Xcopy! Robocopy is designed for robust file copying and is able to recover from errors and retry a user-specified number of times. Although failures using Xcopy are rare, I have seen several instances where a bit has gone AWOL!

If you are experiencing problems with Wait for Program to terminate, you could try an alternative approach. Within an infinite Repeat loop (e.g. repeat until N1 <> N1), do a Repeat With Processes, testing whether the Robocopy (or Xcopy) process is still running. If it isn't running, exit both Repeat loops, otherwise wait 1 or 2 seconds (use the Timed Delay in Seconds command to minimze CPU usage) and try again.

BTW, Robocopy is freely available from Microsoft (it's part of the Windows Resource kit, but can be downloaded without having to purchase that offering).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...