user1200540
user1200540

Reputation:

Is there a way to leech information from a Program i don't control?

Currently running this code to open Business Vision (an application written by someone else that i don't have access to the code of):

ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(BusinessVisionPath);
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();

StreamReader myStreamReader = myProcess.StandardOutput;
Boolean done = false;
while (done == false)
{
    int s = myStreamReader.Read();
    Console.WriteLine(s);
    if (s == -1)
    {
        done = true;
        Process IProcess = new Process();
        ProcessStartInfo IProcessStartInfo = new ProcessStartInfo(QuickPrinterPath);
        IProcessStartInfo.WindowStyle = ProcessWindowStyle.Maximized;
        IProcess.StartInfo = IProcessStartInfo;
        IProcess.Start();
    }

}
myProcess.Close();
Console.ReadLine();

Anyways,

this code currently opens my printer program when BusinessVision closes.

Questions:

  1. How (if possible) can i open my program when a certain message box pops up within BV ("Are you sure you want to print an invoice"?)
  2. Is it possible to get any data from the application ? like raw data that i can parse through as it runs or something?

Upvotes: 0

Views: 191

Answers (5)

Patrick Paquet
Patrick Paquet

Reputation: 161

You can try to use one of the approved way to access data.

In the case of Sage BusinessVision there is:

  1. Data import and export as csv availlable manualy from the application.
  2. Direct acces to the Pervasive database, documentation availlable in the help section of the application in a file called BusinessVision Database Structure Reference.chm
  3. API availlable to Sage partners.

1 is the most simple way and nothing is automatic.
2 is more challenging but will give you acces to the underlying data live.
3 requires that you pay and that you meet requirement by Sage.

If you combine 2. and some UI automation you could build some trigger on certain UI events and bring foward new windows filled with data from the database.

Note that UI automation will be extremly fragile to new version of the application and will certainly need to be reworked every time.

Upvotes: 1

Ben Brandt
Ben Brandt

Reputation: 2921

You might want to look into Microsoft's UI Automation. It allows you to read data from the windows of other applications, and interact with other applications' UI programmatically. I used this a couple years ago to automate a bunch of tests on an old VB6 app we had. My code would find the main window of the application, then drill down to the menus/controls/etc that I was interested in. From there I could automate clicks and keystrokes, and then scrape the text/data I wanted from the labels in various windows. I could then pull the data into my .NET app and do what I wanted with it.

In your case you would need some always-running app (such as a Windows service) to constantly monitor the BV program and detect when the message box appears, and then react accordingly by launching your program.

It takes a fair amount of work to understand and get working, but it's very powerful. There are free apps out there that will make it easier to browse the visual hierarchy of windows and see what kind of information is available. Check out Microsoft's UISpy:

http://msdn.microsoft.com/en-us/library/ms727247.aspx

Here are some other links to get you started:

http://en.wikipedia.org/wiki/Microsoft_UI_Automation

http://msdn.microsoft.com/en-us/library/ms747327.aspx

Upvotes: 1

ElvisLives
ElvisLives

Reputation: 2275

You could always try a decompiler :) dotPeek

Upvotes: 0

Jason Kleban
Jason Kleban

Reputation: 20788

If the target is a .NET exe, perhaps the developers were sloppy and exposed their classes and methods publicly. In that case, load the exe as if it were a DLL dependency for your application and call their methods directly.

Upvotes: 0

Joshua Drake
Joshua Drake

Reputation: 2746

  1. You could, although I'm not sure I'd recommend it, Enumerate top level windows, and check if one of them matches the pop-up box.
  2. Except for files or database entries that the application creates, not that I am aware of, unless you want to get into Binary Patching of the application.

Upvotes: 0

Related Questions