Link to home
Start Free TrialLog in
Avatar of NeillyC
NeillyC

asked on

Getting Console Window Text

Hey Guys

I'm trying to run a dos business app in a console window and capture the screen display that it presents to the user.
Ultimately i'd like to have the contents of the screen inside a string[] or whatever, but i'm not quite sure how i can get this happening.
I'm launching a cmd window, and getting the handle to it just fine, but from there i'm not sure how to get the screen.
It's a graphical app, so it should work for edit.com for example.

Any ideas?
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Avatar of NeillyC
NeillyC

ASKER

Idle thanks for posting but your links are for standard input/output, this needs to be for graphical interface, tests i tried could get these to work.

It seems the answer is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/reading_and_writing_blocks_of_characters_and_attributes.asp

However it's in c++, and i cannot seem to convert it sucessfully to c#

Sorry this has kind of turned in to a conversion question, but it's hard to do this kind of stuff when all the samples around are in c++
You could try the "ConsoleHaker" project posted by METALHEAD1992 here:
http://www.3dbuzz.com/vbforum/showthread.php?t=127871&page=2
Avatar of NeillyC

ASKER

hehe yeah, seen that, but it seems the attach console function only works in XP. is this the case?  I really need it to work on our win2k systems also
On 2k it throws an exception:
Unable to find an entry point named 'AttachConsole' in DLL 'Kernel32.dll'.

Here is the import statement
[DllImport("Kernel32.dll")]
public static extern Boolean AttachConsole(IntPtr dwProcessId);

I've tried rebuilding the dll without the attachconsole reference, but all i seem to be able to return is 0s, so it seems important. Have you heard of anyone who has got this to work on 2k?

Thanks for your work so far idle mind
Apparently it is a very new API:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/attachconsole.asp

At the bottom in the requirements section:
Client Requires Windows Vista or Windows XP.
Server Requires Windows Server "Longhorn" or Windows Server 2003.

=(
Avatar of NeillyC

ASKER

I tried to convert the msdn sample above from c++ to c# because it doesn't require attachconsole, but no go yet, what do you think?

Does anyone else know how i could get this working?
I've never tried to grab the contents from this type of console window.  I'm not even sure I have any applications on my system that do this type of window that I could test with.  I would have to write one from scratch just so can screen scrape it...lol.
What version of .NET are you using?

Bob
Avatar of NeillyC

ASKER

Idle, a good example would be "cmd /c edit"!

Actually i don't know that bob, i've never thought to look cos i haven't needed it, and i don't know how to check.

I'm using a pretty fresh install of vs 2003, so what comes standard with that?

What are you thinking of anyway?
Avatar of NeillyC

ASKER

I investigated that one, i'm using .net 1.1

however i believe we can upgrade to .net 2 without any trouble
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial