Environment.GetCommandLineArgs()[0] question

  • Thread starter Thread starter puzzlecracker
  • Start date Start date
P

puzzlecracker

I use Environment.GetCommandLineArgs()[0] to get the full program
name, including path. However, is there a way to get just a program
name, without preceeding path. Thanks
 
I use Environment.GetCommandLineArgs()[0] to get the full program
name, including path. However, is there a way to get just a program
name, without preceeding path. Thanks

You can use one of the numerous functions in System.IO.Path class to
extract just the filename from a full path.
 
I use Environment.GetCommandLineArgs()[0] to get the full program
name, including path. However, is there a way to get just a program
name, without preceeding path.

System.Reflection.Assembly.GetExecutingAssembly().GetName().Name

Not really - GetExecutingAssembly() returns the assembly to which the
currently executing code belongs; if the original poster's application
consists of more than one, then it's not what he needs (he may get one
of his .dll files rather than the .exe that was used to launch it).

The correct one, should he choose to go down that path, is
Assembly.GetEntryAssembly().
 
Back
Top