0

I'm writing a console app that detects USB drives, formats them, and then runs a program called UnetBootin to write an ISO to the drives. Everything works fine, but the issue is UNetbootin doesn't simply "exit" so .WaitForExit() doesn't work unless the user clicks the "Exit" button.

The only way I can imagine to solve this is either by checking for that button to appear or trying to guess if the process is idling somehow. In either case, I wouldn't know where to start.

enter image description here

Jai
  • 289
  • 6
  • 15

1 Answers1

0

This is going to be ugly no matter how you slice it. I 'm not aware of a better approach, so here is one that would work AFAIK:

  1. Get the PID of your target process (you already have that if you can call WaitForExit)
  2. Get handles to all windows of that process
  3. Use GetWindowText to get the text of each and every window from step 2
  4. If any window has text equal to "Reboot Now", you know you 're done

WARNING: At this point I should mention that GetWindowText should be considered extremely dangerous because it can do evil things to your thread, including hanging it, due to no fault of your own. In practice it won't happen, but it's something you should know.

Community
  • 1
  • 1
Jon
  • 428,835
  • 81
  • 738
  • 806