Reputation: 467
Hopefully someone might point me in the right direction.
So there's a very simple and old Delphi program run on a computer, and I have no access to the source or its DB. I can only run the .exe
I would like a way to somehow read several strings from TEdit controls in this program and dump them to a simple .txt file on the same computer. It also prints the data every time something new comes up, so maybe there's a way to catch it while it's being sent to the printer. This is where my ideas end.
How would I go about doing this? Some kind of listener utility? Win32 API? The OS is Win7.
P.S. It's not for hacking :) so no need to hide anything. Can be in plain sight.
EDIT: Ok, since everyone started focusing on the wrong things, I'll try to explain exactly what I need this for.
First of all, programming is "only" an on and off hobby of mine. And I still consider myself very much a beginner. But whereas before I would just take a huge book on, say, the C language and read it, without getting anything done, and the having life get in the way, now I've decided that maybe a better way would be to have a concrete project in mind and be driven and focused towards it. That way I'll have a specific goal and will try to learn only the things and technologies I need to achieve it. It will also help me in overcoming the confusion of what language/technology to pick out of so many.
That's where my question comes from. My actual job has nothing to do with programming or IT. Nor do we have any access or any say in the software that we use. One of the programs - the one I am talking about - is a simple register: a client comes, our employee adds an entry to the register, and the program prints out (hence I was thinking I could catch the info when sent to printer) two receipts with a number. One goes to the client, the other stays with us. We have a very primitive system in place that allows the client to look up his order status using his receipt number (basically "Done" or "Not done"). The info is stored in a small DB on our website. I do have access to our DB and our info. I do not have any access to the source of register program, nor its DB. I can modify neither. I can only run it. Hence the question.
What we do now is - an employee then literally takes the piece of paper, opens our website and adds the new entry by hand. Then, when the time comes, he changes its status. My idea is to simplify everyone's life: somehow catch the receipt number (and other info) DURING the entry creation process on that Delphi register program (while the client is still there, before our employee click "Ok" and creates the entry), dump it to a .txt file, and later on develop something to automatically upload the info in bulk to our own DB. So that no one has to input it by hand which is pointless and tedious. The problem is that, like I said, I have no access to the program's source or its DB. It's a fact and there's no point in suggesting we change the fact. We can't. I do have access to the physical computer the program runs on, and of course I have access to our website and our DB. Hopefully this makes sense.
Again, my job has nothing to do with IT, so this would be a free time hobby project to get me back into programming but with a specific goal in mind. It seems like a lofty goal but I have no other ideas honestly. That's why I said I am ready to consider any technology and any language. Delphi is tagged only because the register software is Delphi. I actually know very little/nothing about Delphi so if this can be done in some other language (C or .Net or a script of some kind...), I would appreciate the pointers.
Upvotes: 0
Views: 1093
Reputation: 700
I do this all the time to essentially automate a very old app on XP. This is from 2000 and only used on XP.
If it needs to be bullet proof then look into Hooks, madCodeHook is easy but you will need to prove you aren't doing anything a good hacker learns from his buddies in the first five minutes.
Some code to get you started:
function MySendMessageEx(const handle: THandle; const MessageID: Cardinal; const wParam, lParam: integer): integer;
var
ThisThreadID : DWord;
AttachToThreadID : DWord;
begin
ThisThreadID := GetCurrentThreadID;
AttachToThreadID := GetWindowThreadProcessId(handle, nil);
Result := 0;
if ThisThreadID <> AttachToThreadID then
begin
if AttachThreadInput(ThisThreadID, AttachToThreadID, True) then
try
Result := SendMessage(handle, MessageID, wParam, lParam);
finally
AttachThreadInput(ThisThreadID, AttachToThreadID, false);
end;
end;
end;
and:
SetString(Result, Buffer, MySendMessageEx(AHandle, WM_GETTEXT, SizeOf(Buffer), Integer(@Buffer)));
Upvotes: 5