Archive: SetShellVarContext, other than current and all?


SetShellVarContext, other than current and all?
I am creating a .exe that is pushed to a machine, and then installed. However the system that pushes it and fires off the .exe, is admin. I would like to create shortcuts for a specific user.

I know you can use SetShellVarContext, but only for "all" and "current". This does me no good.

Is there a way to create shortcuts for a specific user?

Let's say you have users

admin
joe
lisa
default

How would I create a shortcut for just one of them?


Assuming you want the desktop as an example, the simplest solution would be assuming the directory is in C:\Documents and Settings. But the language can change, so you can use "$APPDATA\..\Desktop". However, the user's profile can be somewhere else, or the desktop's directory could be named differently. So, you can use EnumUsersReg, or some variant of it, to load the registry of the user and read the value from "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop". This value can be missing because the user hasn't logged on yet, or hasn't used the folder in question. To be sure, you can run your installer as the user, or manually use SHGetFolderPath, passing it a token of the user. But for the token to exist, you need to log on the user and for that you need an interactive installation or the password of the user.

The best solution would probably be mounting the user's registry and setting your installer to run on start-up. You could also run a thin client that'd connect to your server with a named pipe so you can use ImpersonateNamedPipeClient and CreateProcessAsUser to run the installer on the user's behalf. If you need administrator rights in the installer, you could use SHGetFolderPath with the impersonation token in your server and pass the result to the installer on the command line.