I need to run a script that requires admin privileges to modify the HKLM part of the registry and system files/folders.
But I also need to interact with the HKCU part of the registry.
The script must be run from a regular account. There is a separate administrative account for privileged actions.
Using the admin account does not have the same access to regular user registry and profile folder.
Is there a way to launch an elevated command prompt using a regular user, providing admin credentials, but keeping the regular user environment?
Thank you
As far as I know, no. Elevation via UAC doesn't ever grant privileges – it only allows the account to regain its "full" privileges that it would normally have without UAC. So if the user is not an Admin then the user is not an Admin and switching to a different user for that process becomes necessary.
Your easiest approach might be to split the script into two parts and have the non-elevated part do HKCU edits – or if absolutely necessary, pass your SID to the elevated part so that it may access your HKCU via
HKEY_USERS\$sid\
instead. (Depending on the language the elevated script is written in, it might use Terminal Services API to determine the username and SID of the logged-in user.)