Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

i have an .exe file which is needed to be started initially as SYSTEM user.
This .exe is calling another instance(copy) of itself, but in user context so that interactive actions can be done (in this case showing a Toast Notification).

Do you have an idea how the first instance of my program can start itself as a second instance from SYSTEM context in user/interactive mode without loosing access to Registry/HKLM ?

Maybe there is an alternative to Registry/HKLM? I just want to share data between the system process and user/interactive process, both need to have read/write access to a common data basis.
I'm new to C#, so i have no idea about alternatives.

Thank you very much!

Best regards
Emanuel

What I have tried:

In Visual Studio 2017 i used StartAsCurrentUser.exe (GitHub - clreinki/StartAsCurrentUser: A simple EXE to utilize the functionality found in https://github.com/murrayju/CreateProcessAsUser to launch another EXE as currently logged in user[^]. And it worked well. Both processes had access to Registry/HKLM.

Now i had to switch to Visual Studio 2019, and it does not work anymore.

If the second process (in interactive mode, startet by StartAsCurrentUser.exe) tries to write a key in the Registry (HKLM), i get the error "Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\RSMGMT\Apps\TestSystemUser' is denied.
Posted
Updated 6-Jul-21 5:27am
Comments
Dave Kreskowiak 6-Jul-21 11:06am    
Don't post he same question in multiple forums. Pick one place and one place only.
Emil12345687 6-Jul-21 11:29am    
Sorry, after i posted it the first time, i didn't find my question anymore, even using my profile....So i posted it again, because i thought, i made something wrong ;-) Next time i will use only the "quick answers" section. Sorry...

That's because HKEY_LOCAL_MACHINE is always a protected space in registry, so you need to either elevate privileges on any process that accesses it, or better not use the registry at all. That's partly why the registry is getting harder and harder to access - every man and his coding dog used it to store everything, and it got huge and unwieldy.

Instead, use a config file that is accessible to both process users without elevation.
 
Share this answer
 
If you are looking to share data that does not need to be "persisted" (i.e. stored on your local disk) then I've used Memory Mapped files in the past, see C# Send Data Between Processes (w/ Memory Mapped File) | coding.vision[^]

But as you are new to C# you might like to stick to using config files as suggested by OriginalGriff - here is a useful resource to get you started - Store custom information from a configuration file - C# | Microsoft Docs[^]
 
Share this answer
 
thank you very much for your quick reponse!
You're right, Registry is not a good place for the needs...
I tried a bit with ConfigurationManager.AppSettings, but wasn't able to get it run properly immediately.
So i decided to solve it witch a classical ini file. A bit old school, i know ;-) but it's simple and is working fine.
Thanks again !
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900