Using ShellExecute to open .mxd - Win 7

2749
7
03-30-2011 12:24 PM
Highlighted
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
Reply
0 Kudos
7 Replies
Highlighted
Regular Contributor III
Since your file name has spaces in it, did you put quotes around it?
Reply
0 Kudos
Highlighted
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) ;
Reply
0 Kudos
Highlighted
Regular Contributor III
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.
Reply
0 Kudos
Highlighted
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!
Reply
0 Kudos
Highlighted
Regular Contributor III
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:(
Reply
0 Kudos
Highlighted
Regular Contributor II
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.
Reply
0 Kudos
Highlighted
New 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();
Reply
0 Kudos