0

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?
  • if the calls to the program are repetitious you could try creating a macro to simulate the keyboard and mouse movements –  Apr 11 '12 at 17:55
  • You can also suspend the process while asking the question by foreach(var t in theProcess.Threads) t.Suspend, etc... – Chibueze Opata Apr 11 '12 at 21:05
  • Also see this, I believe it's a simpler and more direct solution... http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/f6e2219e-d8ee-4a49-bc59-b9a2716c3280/ – Chibueze Opata Apr 11 '12 at 21:14

5 Answers5

1

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

Ben Brandt
  • 2,851
  • 5
  • 34
  • 45
  • 1
    Just so you know - This answer isn't 100% accurate, UISpy is outdated since windows 7 came out. The new one is called 'Inspect' and it comes with the 7.1 sdk –  Apr 12 '12 at 12:05
1

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.

Patrick Paquet
  • 161
  • 1
  • 3
0
  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.
Joshua Drake
  • 2,704
  • 3
  • 35
  • 54
0

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.

Jason Kleban
  • 20,024
  • 18
  • 75
  • 125
  • This was a really good idea! i tried it but unfortunately they weren't sloppy –  Apr 11 '12 at 18:01
  • Well this technique might still work by using reflection to access unexposed members anyway. This would be very hackish and easily broken, but since you're already considering such a strategy pick the simplest approach. – Jason Kleban Apr 13 '12 at 19:13
0

You could always try a decompiler :) dotPeek

ElvisLives
  • 2,275
  • 2
  • 18
  • 24
  • mmm,... it's a pretty complex program, i doubt that a decompiler will decompile it correctly, and it's copyright, isn't that illegal? –  Apr 11 '12 at 18:00
  • There aren't any decompilation police patrols to fear. If you use the information to figure out how to interoperate with it in a license-compatible way, I don't think it's bad. If you incorporate their code as decompiled into yours and not use theirs anymore, that would be questionable. – Jason Kleban Apr 13 '12 at 19:11