-
Notifications
You must be signed in to change notification settings - Fork 813
Open
Description
Hi,
after extracted my application is running as Administrator mode because zip extractor is running as admin so that my application also as same privileges but want to execute normal mode
how can i execute my application without admin privileges after zip extraction ?
i will get an another error in web browser
this site is not secure ....
Thanks
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
Select code repository
Activity
NeilMJohnson commentedon Oct 9, 2019
Hi, I am having the same problem. My users are not privileged, so the zip upgrade prompts for a privileged username/password to perform the upgrade (as it should). However, when the application is restarted, it still runs under the privileged user account, rather than the original users account. The user then needs to remember to shut the application down again and restart it. Many times they forget, and then a whole host of functions stop working including our email reporting of problems in the event log. I would be useful if the application restarts under the current user account, rather than the privileged users account.
Thanks
DjordjeMandic commentedon Oct 9, 2019
Write piece of code in your application that checks if application is run as administrator:
Then if it returns true just use code from Jonathan.Peppers:
Jonathan.Peppers also explained how it works:
That above should solve your problem, you can also use
ProcessStartInfo
to run the app under user that you want but then you need to know username and password or you could grab the primary token and environment block from the process that you like and changeprivate static bool LaunchProcessAsUser(string cmdLine, IntPtr token, IntPtr envBlock)
from private to public and call it with correct arguments.
But be careful, if explorer.exe is run as another user, not current user, then program will run under the user that explorer.exe is running.
NeilMJohnson commentedon Oct 10, 2019
Hi Djordje, thanks for your reply. I had tried something like this, but my application is in VB and is a Single Instance Application. Therefore, the Launch does not work, as I immediately ends, before I can close my current instance. It would be useful if the ZIP Extractor did this for me, otherwise I am going to have to write another program that handles the restart, so the application will get started twice, rather than once.
Neil
DjordjeMandic commentedon Oct 12, 2019
@NeilMJohnson Well add a little startup delay about 200ms to allow old process to exit. Im also using it with single instance application (mutex used to check if app is already running) and it has no problems restarting itself. Clone the repo then and modify the start method by replacing it with
ProcessAsUser.Launch(string path)
. It can be written in vb easily. Its all .NETAlexBrunnerACAG commentedon Aug 21, 2020
I all,
maybe I lost some piece of code but I don't really understand how to update the application as administrator but restarting it without admin rights.
Can someone please help me to get this fixed?
@DjordjeMandic - I cannot see where in AutoUpdater I should place this code you mentioned.
Any help would kindly be appreciated.
Best regards,
Alex
DjordjeMandic commentedon Sep 7, 2020
@AlexBrunnerACAG put it at begging of ur program. let that be the first thing it does
AlexBrunnerACAG commentedon Sep 7, 2020
AlexBrunnerACAG commentedon Oct 29, 2020
Hi @DjordjeMandic
I have tried to get the restart running for many days now.
I am not able to do that because it isn't as simple as you mentioned.
Restarting an application with normal privileges, if it is running with elevated privileges, seems to be a very hard task to do.
You have to take care of all the environment settings like UAC as well.
I would really appreciate if AutoUpdater.NET would be able to do that out of the box.
Best regards,
Alex
DjordjeMandic commentedon Oct 29, 2020
@AlexBrunnerACAG Try this solution from github. I'm not the creator neither the participant in source code of this library.
AlexBrunnerACAG commentedon Nov 3, 2020
Hi @DjordjeMandic
You are my hero. Based on you hint I was able to implement the behavior.
Thank you very much.
To help others implementing this I will add the complete code here.
I also added support for arguments which is very important for us.
The entry point:
The UACHelper class:
And the class ProcessSupport: