Autorun app automatically at windows start

M Indra Ruslan 241 Reputation points
2021-06-24T05:55:24.897+00:00

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#
{count} votes

2 answers

Sort by: Most helpful
  1. Lex Li (Microsoft) 6,037 Reputation points Microsoft Employee
    2021-06-24T07:16:12.03+00:00

    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).

    0 comments No comments

  2. 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.