如何检测应用程序是从控制台启动还是从"资源管理器"启动?
我想做的是,如果应用程序从CMD启动,然后显示一点关于CMD的信息,只有当应用程序从CMD启动并且没有任何参数,所以我无法检测参数。
项目是一个windows窗体
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