Using ShellExecute to open .mxd - Win 7

3095
7
03-30-2011 12:24 PM
DavidKroll
New Contributor
I have a Delphi application that calls ShellExecute on a .mxd file.  It works fine in XP, but when trying to run on Win 7, ArcMap throws the error "Could not find file C:\users\username\My Documents\filename.mxd.mxd".  I'm not passing the filename with 2 .mxd's at the end.  Anyone have any ideas?

Thanks,

David
0 Kudos
7 Replies
RichardWatson
Frequent Contributor
Since your file name has spaces in it, did you put quotes around it?
0 Kudos
DavidKroll
New Contributor
I'm using a variable in the ShellExecute, so there's not an actual filename.

  ShellExecute(Handle, 'open', PChar(FileNameVariable), nil, nil, SW_SHOWNORMAL) ;
0 Kudos
RichardWatson
Frequent Contributor
So the obvious question is what is the contents of FileNameVariable?

If you literally type that into the Windows Start menu Run command does it work?

Try a file path which does not have spaces in it.
0 Kudos
DavidKroll
New Contributor
Typing it in at the command prompt didn't work, so I moved the file to a path with no spaces and it works.  Just amazes me how this works in XP but not 7.  Oh well.

Thank you for your help!
0 Kudos
RichardWatson
Frequent Contributor
It should work from ShellExecute as well.  If the filename has spaces in it then you need to protect it by enclosing it in quotes.

In C#:

            string fileName = @"""c:\file path\file name with spaces.mxd""";

It has been too long since I have written Pascal:(
0 Kudos
MichaelRobb
Occasional Contributor III
wow, shell... old school
windows 7 structures program files differently as well as user folders... (x86 for starters)
so USERNAME is going to be a different path...
As richard states, should work, try throwing the MXD is a simple folder path to test.
0 Kudos
JoeMadrigal
New Contributor III
This works for me using the process class instead.  I do not include the ".mxd" in my mapName variable.

System.Diagnostics.Process arcmap = new System.Diagnostics.Process();

arcmap.StartInfo.FileName = arcmappath + "\\arcmap.exe";
arcmap.StartInfo.Arguments = path + mapName;

arcmap.Start();
0 Kudos