ArcMap Command Line Arguments

4926
6
10-04-2011 02:15 AM
PascalCoulon
New Contributor II
Hello There,

Is there a way in .Net (c#) to get access to command line argument passed to ArcMap on starting the application. I use an extension and I wish to run ArcMap the following way:

"C:\Program Files (x86)\ArcGIS\Desktop10.0\Bin\ArcMap.exe test.xmd param2 param3".

Pascal
0 Kudos
6 Replies
JeffreyHamblin
New Contributor III
If you want to pass these command line arguments for debugging, then in Visual Studio open the project options and select the Debug tab page, where you will find a "Command line arguments" option.
0 Kudos
AlexanderGray
Occasional Contributor III
The only way I see this working is if you write your own exe that starts ArcMap (by creating the application) and sets the values on the extension after arcmap finished starting.
0 Kudos
JeffreyHamblin
New Contributor III
I see I mis-read the original post and earlier replied with just setting a debugging command line.

If you want access to your own additional arguments passed on ArcMap's command  line, then I found something on StackOverflow that might work for you:


string wmiQuery = string.Format("select CommandLine from Win32_Process where Name='{0}'", "ArcMap.exe");
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(wmiQuery);
System.Management.ManagementObjectCollection retObjectCollection = searcher.Get();
foreach (System.Management.ManagementObject retObject in retObjectCollection)
    System.Diagnostics.Debug.WriteLine(">>>>" + retObject["CommandLine"]);


I tried this and can see a map document path and any additional params passed to ArcMap. How reliable this will be, I do not know.

Note that this can be used to get the command-line for any running process.
0 Kudos
JeffreyHamblin
New Contributor III
After looking into this more, I think this is a better solution than the WMI version I posted.

This will get the command-line arguments for the current process, which will allow your extension to get ArcMap's:

string[] args = Environment.GetCommandLineArgs();
PascalCoulon
New Contributor II
Jeff,

Thanks very much for your latest reply. I can confirm that it will work; thought ArcMap expect the path to a valid MXD as the first parameter.

Cheers,

Pascal
AlexanderGray
Occasional Contributor III
thanks jeff that is useful to me too.
0 Kudos