현재 실행중인 프로그램의 이름, 즉 프로그램의 실행 파일 이름을 얻고 싶습니다. C / C ++에서는에서 가져옵니다 args[0]
.
답변
System.AppDomain.CurrentDomain.FriendlyName
답변
System.AppDomain.CurrentDomain.FriendlyName
-확장자가있는 파일 이름을 반환합니다 (예 : MyApp.exe).
System.Diagnostics.Process.GetCurrentProcess().ProcessName
– 확장자가 없는 파일 이름 (예 : MyApp)을 반환합니다 .
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
-전체 경로와 파일 이름을 반환합니다 (예 : C : \ Examples \ Processes \ MyApp.exe). 그런 다음 이것을 전달 System.IO.Path.GetFileName()
하거나 System.IO.Path.GetFileNameWithoutExtension()
위와 동일한 결과를 얻을 수 있습니다.
답변
System.Diagnostics.Process.GetCurrentProcess()
현재 실행중인 프로세스를 가져옵니다. ProcessName
속성을 사용 하여 이름을 알아낼 수 있습니다 . 아래는 샘플 콘솔 앱입니다.
using System;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Process.GetCurrentProcess().ProcessName);
Console.ReadLine();
}
}
답변
이것으로 충분합니다 :
Environment.GetCommandLineArgs()[0];
답변
이것은 나를 위해 일한 코드입니다.
string fullName = Assembly.GetEntryAssembly().Location;
string myName = Path.GetFileNameWithoutExtension(fullName);
위의 모든 예제는 vshost 또는 실행중인 dll 이름을 가진 processName을 제공했습니다.
답변
이 시도:
System.Reflection.Assembly.GetExecutingAssembly()
System.Reflection.Assembly
현재 애플리케이션에 대해 알고 싶은 모든 데이터가 있는 인스턴스를 반환합니다 . 나는 그 Location
속성이 당신이 구체적으로 추구 한 것을 얻을 수 있다고 생각합니다 .
답변
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name;
앱의 FileName을 제공합니다. “MyApplication.exe”
