tags:

views:

1072

answers:

3

Hi!

I have a console application (MyProgram.EXE) that references a Utilities assembly.

In my Utilities assembly, I have code that does:

Dim asm As Assembly = Assembly.GetExecutingAssembly()
Dim location As String = asm.Location
Dim appName As String = System.IO.Path.GetDirectoryName(location)
Conole.WriteLine("AppName is: {0}", appName)

When I call it from MyProgram.EXE, I receive "AppName is: Utilities.dll"

What I want is "AppName is: MyProgram.EXE"

What am I doing wrong?

+3  A: 

Use GetEntryAssembly() instead to get the assembly containing the entry point.

The better way to do it is using System.Environment.CommandLine property instead.

Specifically:

Dim location As String = System.Environment.GetCommandLineArgs()(0)
Dim appName As String = System.IO.Path.GetFileName(location)
Conole.WriteLine("AppName is: {0}", appName)

By the way, you want to use GetFileName instead of GetDirectoryName

Mehrdad Afshari
A: 

Mehrdad,

You are correct, my bad. I do want GetFileName instead of GetDirectoryName.

Thank you.

coson

A: 

Hi I want to do the same job but I want name of all other applications running at a particular time

Please update this for me I shall be thank full to you

John Saunders