views:

21

answers:

1

I need to write a shortcut in the automatic startup folder for all users.

The scenario is that a user with administrator privileges, through the configuration dialog of the application, must be able to set the application to start automatically for all normal users when they log in.

I get the startup folder using

SHGetSpecialFolderPath(NULL, startFolderPath, CSIDL_COMMON_STARTUP, FALSE)

but then I don't have write privileges on that folder, even when the logged user is part of the Adminisrator's group.

I suppose I need to call some API function related to User Account Control (UAC) to ask permission to the logged user to elevate the current privilege.

This should work on Windows XP too

+1  A: 

When you say you don't have write privileges on the folder, was the app or tool you were using to write running elevated? That is, running as admin? This is not the same as being run by an account that is an administrator. If not, right click the exe and choose Run As Administrator. This will elevate the app and probably enable it to complete the configuration task.

This is not related to User Access Control or Code Access Security. It's UAC that protects HKLM, Program Files, and other all-users, per-machine settings.

Kate Gregory
Thanks, I mistook UAC to be User Access Control. I'll correct it as User Account Control in my original question.
sergiom
I do not want my application to be Run As Administrator. I just want to elevate privileges only for the short amount of time needed to create the shortcut. I want to display the UAC Window to ask user permission to change protected settings, like setup programs do.
sergiom
That's what I'm saying, too. The thing that writes to the registry needs to be elevated. If you want that to elevate and the rest not, put it in a separate exe, put a manifest on it with requireAdministrator, and use ShellExecute to launch it.
Kate Gregory
OMG. That's more complicated than what I expected. Thank you very much.
sergiom