Select to view content in your preferred language

Using ShellExecute to open .mxd - Win 7

3334
7
03-30-2011 12:24 PM
DavidKroll
Emerging 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
Deactivated User
Since your file name has spaces in it, did you put quotes around it?
0 Kudos
DavidKroll
Emerging 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
Deactivated User
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
Emerging 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
Deactivated User
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
Honored Contributor
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
Occasional Contributor
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