Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: External exe cannot access user path



Permlink Replies: 4 - Last Post: Apr 22, 2015 11:22 PM Last Post By: Gerrit Beuze Threads: [ Previous | Next ]
Gerrit Beuze

Posts: 70
Registered: 10/16/00
External exe cannot access user path
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 22, 2015 5:58 AM
Hi,

I'm trying to add support for a user definable external image viewer - such as mspaint.exe
To invoke this viewer I use
ShellExecute(0, nil, PChar(ExternalViewerPath), PChar(FileName), nil, SW_SHOWNORMAL);

with ExternalViewerPath for example 'C:\Windows\System32\mspaint.exe'
This works OK as long as FileName is in a directory like
'E:\Dropbox\Images\image.png'

But this fails when the image is stored in the user app data dir - for example:
C:\Users\[USER NAME]\AppData\Local\ModelMakerTools\SimpleMind\1.0\.cache\providers\smmx_0\image.png

MSPaint is executed OK, (ShellExecute returns a valid result) but paint itself displays an error
message: "Access denied: C:\Users\[USER NAME]"

The calling executable itself is allowed to access the file OK.

Is there a way around this? for example by to giving the viewer (mspaint in the example)
the same rights as the executable that calls ShellExecute?

Thanks in advance,

Gerrit Beuze
ModelMaker Tools
Robert Triest

Posts: 687
Registered: 3/24/05
Re: External exe cannot access user path
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 22, 2015 7:23 AM   in response to: Gerrit Beuze in response to: Gerrit Beuze
There might be problems because of spaces in the filename/path of the FileName Param.

Try to put double quotes around the filename

ShellExecute(0, nil, PChar( 'C:\Windows\System32\mspaint.exe'), PChar('"C:\Users\[USER NAME]\AppData\Local\ModelMakerTools\SimpleMind\1.0\.cache\providers\smmx_0\image.png"'), nil, SW_SHOWNORMAL);
Robert Triest

Posts: 687
Registered: 3/24/05
Re: External exe cannot access user path
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 22, 2015 7:47 AM   in response to: Robert Triest in response to: Robert Triest
indeed it has problems but I don't get Access Denied error only Can't Open Error.

not working:
ShellExecute(0, nil, PChar('C:\Windows\System32\mspaint.exe'), PChar('C:\Users\All Users\Microsoft\OFFICE\AssetLibrary.ico'), nil, SW_SHOWNORMAL);

OK:
ShellExecute(0, nil, PChar('C:\Windows\System32\mspaint.exe'), PChar('"C:\Users\All Users\Microsoft\OFFICE\AssetLibrary.ico"'), nil, SW_SHOWNORMAL);
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: External exe cannot access user path
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 22, 2015 9:52 AM   in response to: Robert Triest in response to: Robert Triest
Robert wrote:

Try to put double quotes around the filename

Since the user's code is using variables for the filenames, use the AnsiQuotedStr()
function to add quotes to them:

ShellExecute(0, nil, PChar(AnsiQuotedStr(ExternalViewerPath, '"')), PChar(AnsiQuotedStr(FileName, 
'"')), nil, SW_SHOWNORMAL);


--
Remy Lebeau (TeamB)
Gerrit Beuze

Posts: 70
Registered: 10/16/00
Re: External exe cannot access user path
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 22, 2015 11:22 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Robert, Remy,

Yes, adding AnsiQuotedStr (2x) indeed solves the problem.

Thanks a lot,

Gerrit Beuze
ModelMaker Tools


Robert wrote:

Try to put double quotes around the filename

Since the user's code is using variables for the filenames, use the AnsiQuotedStr()
function to add quotes to them:

ShellExecute(0, nil, PChar(AnsiQuotedStr(ExternalViewerPath, '"')), PChar(AnsiQuotedStr(FileName, 
'"')), nil, SW_SHOWNORMAL);
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02