1
votes

I'm using ShellExecute(NULL, L"open", szSomeDirectory, 0, 0, SW_SHOWDEFAULT) to open a directory in explorer.

I'm trying to open a directory that I would normally be prompted with You currently do not have permission to access this folder. and would give me option to get access and show a UAC prompt.

When I'm executing ShellExecute, Explorer gives me a error message saying Access Denied.

My program is running with administrator privileges but that doesn't seem to matter.

How can I get access to open this folder?

2
Try right clicking the program .exe and selecting Run As administrator. Depending on your OS, even though you are logged on as administrator it does necessarily mean all processes you start run with elevated privileges.hmjd
I've tried that. I think because the "open" verb is just telling explorer to navigate to the directory. Explorer is giving me the access denied message.Josh
You probably need to run explorer elevated. This should do it: ShellExecute(NULL, L"runas", L"explorer", szSomeDirectory, 0, SW_SHOWDEFAULT)David Heffernan
That doesn't work unfortunately. Maybe this will help: `C:\Dir1\Dir2\Dir3` - Dir2 I don't have access to by default. I'm trying to open Dir3 in my program.Josh

2 Answers

1
votes

Figured it out.

My user account didn't have access to the file.

My solution was to use AccessCheck before ShellExecute to see if I could access the file, and if I couldn't, use SetNamedSecurityInfo to add an ACE for the logon user account with full access.

0
votes

you can set the UAC level in the linker manifest for your program.

Take a look at this: Strange file-permissions if apps run as administrator