The best option is to split your app to multiple executable binaries so that they each run as desired user accounts (admin and non-admin).
Autorun app automatically at windows start
Hello, my name is Indra,
Recently I created an app that places the Regedit value tells to run the app automatically at windows start.
Before the app run, it asked for admin authentication.
When the app run and I checked at the registry the value didn't write to the
following path --> "HKEY_Current_user\Software\Microsoft\Windows\CurrentVersion\Run"
but it writes to the admin user profile.
my question, how to set the value path to the current user under admin?
thanks
Developer technologies C#
2 answers
Sort by: Most helpful
-
Lex Li (Microsoft) 6,037 Reputation points Microsoft Employee
2021-06-24T07:16:12.03+00:00 -
RLWA32 49,536 Reputation points
2021-06-24T17:06:46.99+00:00 When a standard user runs an application that requires Administrator privileges and successfully provides the necessary credentials the application runs in the context of that Administrator account. That is why registry access with HKEY_CURRENT_USER references the registry hive of the Administrator account instead of the logged on standard user.
In order to reference the standard user's registry hive from the elevated process two things need to happen.
First, the elevated process must impersonate the logged on user. Then the impersonating thread should call RegOpenCurrentUser to obtain a handle to the registry hive for the logged on standard user. This key can then be used for registry access.I tried to post sample code but the Q&A site refused to allow it.