1

How I can detect if my application is launched from the console, or from "explorer"?

What I want to do is, if application is launched from CMD then show a little info on CMD, only if application is launched from CMD and without any arguments so I can't detect the arguments.

The project is a Windowsform.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 2
    http://stackoverflow.com/questions/3527555/how-can-you-determine-how-a-console-application-was-launched – Pacha Apr 29 '13 at 06:39

1 Answers1

0

VB Code:

#Region " App Is Launched From CMD? "

    ' [ App Is Launched From CMD? Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples:
    ' MsgBox(App_Is_Launched_From_CMD)
    ' If App_Is_Launched_From_CMD() Then Console.WriteLine("Help for this application: ...")

    Declare Function AttachConsole Lib "kernel32.dll" (ByVal dwProcessId As Int32) As Boolean
    Declare Function FreeConsole Lib "kernel32.dll" () As Boolean

    Private Function App_Is_Launched_From_CMD()
        If AttachConsole(-1) Then
            FreeConsole()
            Return True
        Else
            Return False
        End If
    End Function

#End Region
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417