1

如何检测我的应用程序是从控制台启动还是从“资源管理器”启动?

我想要做的是,如果应用程序是从 CMD 启动的,那么在 CMD 上显示一些信息,只有当应用程序是从 CMD 启动并且没有任何参数,所以我无法检测到参数。

该项目是一个Windowsform。

4

1 回答 1

0

VB代码:

#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
于 2013-04-29T08:13:23.770 回答