All Things WinBatch > WinBatch

Control WinBatch from .NET and return results.

(1/2) > >>

Hello.  I need to initiate a WinBatch script from a .NET application.  The WinBatch script will control another desktop application and should pass back to the parent .NET process details about what it is doing and finding.  For example it should pass back to .NET the text it discovers in certain text-boxes of the Desktop application.  How can I do this please?

You will need to learn about a concept called "Inter-Process Communication", or IPC for short, and then learn about the specific details about how to use the IPC mechanisms that are present on Windows.

The most basic thing you could do is have the WinBatch script write status information to a file and have the .NET application poll a directory for changes and then read the status files as they are written.

A more sophisticated way would be to create a "named pipe" as a server in the .NET application and then have the WinBatch script open the same named pipe as a client.  From that point, the two programs would then communicate a full-duplex bi-directional manner passing messages back & forth.  It's entirely up to you to define the format & content of those messages.  I'd strongly suggest something simple and text-based like JSON.

Alternatively, you could investigate how to use System.Windows.Automation in .NET and control the target application directly from the .NET application and eliminate the need for a separate WinBatch script.  And, likewise, if WinBatch can perform the same functionality as the .NET application, then there is the possibility of eliminating the .NET application and doing everything from within a single WinBatch script.  WinBatch has access to nearly all of the functionality of .NET via it's ability to utilize .NET's CLR [Common Language Runtime].

Perfect Analysis.  Would hope OP would choose door #3 and ask could be explored with CLR.

Thank you.  For the sake of completeness how about any of the following:

Can a WinBatch script be converted to a DLL so .NET could call methods in the DLL?
Can a WinBatch script expose a COM interface for .NET to use?
Can a WinBatch script write to stdout, for .NET to consume?

Tony or Chuck should answer your latest questions. What is interesting is you are asking about Winbatch being called from .NET, rather than the other way around. Or, I misread your ask.


[0] Message Index

[#] Next page

Go to full version