How do I auto-start a program for a specific user using the CurrentVersion\Run key in the registry?

StackOverflow https://stackoverflow.com/questions/16185165

Pergunta

I have a 32-bit application that writes to:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

my application path so that it will be started when the current user logs on. This works fine on 32-bit systems (i.e. the application auto-starts).

I understand that on 64-bit systems, registry redirection comes into play. So, I searched for:

HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run

but the CurrentVersion sub-key does not exist (the Wow6432Node key exists though)! So, I manually created it and my application wrote correctly to the registry (I went into the registry and checked. The entry was there). BUT, the application did not auto-start when the current user logged in. Can someone tell me why?

Btw, all this is fine if I use the HKEY_LOCAL_MACHINE branch. But, I want this to be user-specific.

Why am I not just using the Startup folder?

When UAC is enabled and set to always notify, this simply does not work (i.e. my application does not auto-start). And no, I cannot disable UAC. I require that my application play nice with UAC enabled and set to always notify.

If someone can tell me why, I will gladly forget my need to use the registry (I hate the registry).

Fallback option (last resort):

I will use the Task Scheduler APIs to do this. But, I will do this only when there is absolutely no other way.

Thanks!

Foi útil?

Solução 2

It is not possible to launch an executable requiring elevation from the user's Run key or from the Startup folder. See Elevations Are Now Blocked in the User's Logon Path from the UAC team's blog.

The best solution is probably to configure the executable to not require elevation. It can then launch an elevated copy of itself only if and when actually needed. Or you could use a service for the tasks that require elevation, this is the only good approach if you need to be able to perform elevated tasks on behalf of users who do not have administrator privilege.

Another option, since you can successfully launch the process using HKLM, would be to have it launch for all users but exit immediately if it isn't the user(s) you want.

Outras dicas

HKEY_CURRENT_USER is shared between 32-bit and 64-bit applications (there is no redirection and Wow6432Node key). Here is the list with Registry Keys Affected by WOW64.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top