Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The VB.Net team has done much more to ease things for the developer regarding instrumentation of windows, and I see no problem adding a reference to a VB dll and use that in your C# program.</p> <p>It's two teams with different focus, that's all. And you shouldn't feel bad about using Microsoft.VisualBasic.Interaction.Shell if it solves your issue.</p> <p>You can also use Reflector to see the actual implementation and implement the code yourself if you don't want to reference the dll.</p> <p><em>[Edit - added code example after comment to show you can combine Interaction.Shell and Process]</em></p> <pre><code>int pid = Interaction.Shell("notepad.exe", AppWinStyle.NormalFocus); Process p = Process.GetProcessById(pid); p.Exited += ((o, e) =&gt; Console.WriteLine("Exit")); p.EnableRaisingEvents = true; Console.ReadLine(); </code></pre> <p>Here I use the Shell method to kick off the process, get a handle to the process from the pid, and hook on events. You can even do p.Kill() in order to abort the process.</p> <p><em>[Edit - workaround for cmd.exe]</em></p> <p>It's starting to become a bit hackish to my taste, but it works. Replace "NEWWINDOW" with a random guid or something to make it unique.</p> <pre><code>Microsoft.VisualBasic.Interaction.Shell(@"cmd.exe /c ""start cmd.exe /k title NEWWINDOW""", AppWinStyle.NormalFocus); foreach (var process in Process.GetProcessesByName("cmd")) { if (process.MainWindowTitle.EndsWith("NEWWINDOW")) { process.Exited += ((o, e) =&gt; Console.WriteLine("Exit")); process.EnableRaisingEvents = true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload