Home All Groups Group Topic Archive Search About

Can we determine at runtime if app is Console or Windows?

Author
9 Oct 2006 2:38 AM
Tom Leylan
Hi all, and to Cor, Herfried and the other "old folks", it's been a long
time :-)

I might be hanging around again for awhile but in the meantime I have a
question.  Does anybody know of a way to determine at runtime whether the
app is a console or a GUI app?  I have to imagine the information is
available but searching around didn't yield the answer.

Thanks,
Tom

Author
9 Oct 2006 3:45 AM
Cor Ligthert [MVP]
Hi Tom,

Good to see you back, in my idea is this a typical Herfried question.
I am almost sure he knows this.

Cor

Show quoteHide quote
"Tom Leylan" <gee@iamtiredofspam.com> schreef in bericht
news:%23J$yDw06GHA.348@TK2MSFTNGP02.phx.gbl...
> Hi all, and to Cor, Herfried and the other "old folks", it's been a long
> time :-)
>
> I might be hanging around again for awhile but in the meantime I have a
> question.  Does anybody know of a way to determine at runtime whether the
> app is a console or a GUI app?  I have to imagine the information is
> available but searching around didn't yield the answer.
>
> Thanks,
> Tom
>
>
>
>
Author
9 Oct 2006 4:44 AM
Tom Leylan
Hi to you too... (you're an MVP now)!

It might sound a little funny since it must be known at compile time whether
it is a console app.  On the other hand I was hoping that I might develop a
few routines that would adapt depending upon whether it was a console app,
so I would like to check at runtime.  It might not turn out to be too useful
but I thought I'd check.

Anything else been going on?


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:erwc1U16GHA.4604@TK2MSFTNGP03.phx.gbl...
> Hi Tom,
>
> Good to see you back, in my idea is this a typical Herfried question.
> I am almost sure he knows this.
>
> Cor
>
> "Tom Leylan" <gee@iamtiredofspam.com> schreef in bericht
> news:%23J$yDw06GHA.348@TK2MSFTNGP02.phx.gbl...
>> Hi all, and to Cor, Herfried and the other "old folks", it's been a long
>> time :-)
>>
>> I might be hanging around again for awhile but in the meantime I have a
>> question.  Does anybody know of a way to determine at runtime whether the
>> app is a console or a GUI app?  I have to imagine the information is
>> available but searching around didn't yield the answer.
>>
>> Thanks,
>> Tom
Author
9 Oct 2006 8:04 PM
Oenone
Tom Leylan wrote:
> I might be hanging around again for awhile but in the meantime I have
> a question.  Does anybody know of a way to determine at runtime
> whether the app is a console or a GUI app?

Seeing as no one else has answered, I'll offer you this solution. I don't
like it at all, but it does work (tested in VB2005):

\\\
    Public Function IsConsole() As Boolean

        Dim s As String

        Try
            s = Console.Title
            Return True
        Catch ex As System.IO.IOException
            Return False
        End Try

    End Function
///

I'd strongly advise keeping this in a self-contained function, and then when
someone suggests a proper implementation you can just swap the code over. :)

--

(O)enone
Author
10 Oct 2006 2:08 AM
Tom Leylan
That works well enough.  I agree that catching the exception isn't the idea
method but the functionality is isolated.  I added a static variable within
the function so it can be set once on the first call and subsequent calls
don't need to trip the exception again.

Thanks... it works!


Show quoteHide quote
"Oenone" <oen***@nowhere.com> wrote in message
news:FXxWg.9303$Or2.1939@newsfe7-gui.ntli.net...
> Tom Leylan wrote:
>> I might be hanging around again for awhile but in the meantime I have
>> a question.  Does anybody know of a way to determine at runtime
>> whether the app is a console or a GUI app?
>
> Seeing as no one else has answered, I'll offer you this solution. I don't
> like it at all, but it does work (tested in VB2005):
>
> \\\
>    Public Function IsConsole() As Boolean
>
>        Dim s As String
>
>        Try
>            s = Console.Title
>            Return True
>        Catch ex As System.IO.IOException
>            Return False
>        End Try
>
>    End Function
> ///
>
> I'd strongly advise keeping this in a self-contained function, and then
> when someone suggests a proper implementation you can just swap the code
> over. :)
>
> --
>
> (O)enone
>