473,413 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

How does one get the application name of a C# program at runtime

Hi,

How do I get the application name during run time. In C or C++ I use
argv[0], but in C# args[0] contains the first argument to the program
not the program name. So, what is the magic to getting this?

Thanks,
Andy
Aug 5 '08 #1
5 1703
Andrew Falanga wrote:
How do I get the application name during run time. In C or C++ I use
argv[0], but in C# args[0] contains the first argument to the program
not the program name. So, what is the magic to getting this?
Environment.GetCommandLineArgs().

--
J.
Aug 5 '08 #2
Andrew Falanga <af******@gmail.comwrote:
How do I get the application name during run time. In C or C++ I use
argv[0], but in C# args[0] contains the first argument to the program
not the program name. So, what is the magic to getting this?
You can use Application.ExecutablePath - it's in System.Windows.Forms,
but it works for console apps too.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Aug 5 '08 #3
"Andrew Falanga" <af******@gmail.comwrote in message
news:27**********************************@j22g2000 hsf.googlegroups.com...
Hi,

How do I get the application name during run time. In C or C++ I use
argv[0], but in C# args[0] contains the first argument to the program
not the program name. So, what is the magic to getting this?

Here's another one

String thismodulefilenamestr =
System.IO.Path.GetFileName(System.Reflection.Assem bly.GetExecutingAssembly().Location);

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

>
Thanks,
Andy
Aug 5 '08 #4

"Andrew Falanga" <af******@gmail.comwrote in message
news:27**********************************@j22g2000 hsf.googlegroups.com...
Hi,

How do I get the application name during run time. In C or C++ I use
argv[0], but in C# args[0] contains the first argument to the program
not the program name. So, what is the magic to getting this?

There may be an easier way, but this works:

String thismodulefilenamestr =
System.IO.Path.GetFileName(System.Diagnostics.Proc ess.GetCurrentProcess().MainModule.FileName);

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
>
Thanks,
Andy
Aug 5 '08 #5
Jon Skeet [C# MVP] wrote:
Andrew Falanga <af******@gmail.comwrote:
>How do I get the application name during run time. In C or C++ I use
argv[0], but in C# args[0] contains the first argument to the program
not the program name. So, what is the magic to getting this?

You can use Application.ExecutablePath - it's in System.Windows.Forms,
but it works for console apps too.
Or if you really want, you can use:

new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPat h

(Application.ExecutablePath is much easier though)

Alun Harford
Aug 5 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexey Kouzmitch | last post by:
Hi, I wrote a console application which is called from a SQL Server job. The application utilizes a COM object, to pump data from a legacy (not very old however) application to SQL server. The...
75
by: Beni | last post by:
I have been programming in C for about a year now. It sounds silly, but I never took the time to question why a C(or C++ or Java) program execution begins only at the main(). Is it a convention or...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
4
by: Rick | last post by:
I have a VB.Net 2005 application that I am publishing to a network file server. The app reads an xml file that has some database connection information in it. This xml file is located in the...
0
by: taffer23 | last post by:
ok i want to write a c# program for rapidshare ,the purpose of this program is to restart rapidshare when it raises an error message,(that i cant get rid off.)so i need to put a handle on the...
0
by: taffer23 | last post by:
ok i want to write a c# program for rapidshare ,the purpose of this program is to restart rapidshare when it raises an error message,(that i cant get rid off.)so i need to put a handle on the...
1
by: kfry | last post by:
I am having an issue maybe someone can help with. I have written an application with Access 2003 on my XP pc. I then package it and install it on my VISTA Access 2007 PC. When I do this the wrong...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.