简体   繁体   中英

install as administrator but run as current user

my installer run as administrator, but on complete i want the exe to run as current user.

i am using nsis and already tried UAC

!insertmacro UAC_AsUser_ExecShell "" "some.exe" "" "" ""

but still it run as administrator.

tried to use task scheduler

                    string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
                td.Actions.Add(new ExecAction("" + path + "", "", null));
                td.Settings.DisallowStartIfOnBatteries = false;
                td.Settings.AllowHardTerminate = false;
                td.Settings.StopIfGoingOnBatteries = false;
                td.Settings.ExecutionTimeLimit = System.TimeSpan.Zero;
                td.Settings.IdleSettings.StopOnIdleEnd = false;
                // Register the task in the root folder
                ts.RootFolder.RegisterTaskDefinition("task", td);

but the task also goto administrator and i cant get it to current user.

any ideas ?

My personal recommendation is that you just remove the option to run your application at the end of your installer. The user can just start it from the start menu, it should be highlighted as new and everything.

As you probably know, UAC really changed how common it is for applications to run as a different user than the "logged in" user. You just have to deal with the fact that UAC exists and decide if you feel it is worth the amount of time required to work around it and possible bugs and issues that might arise.

There are at least 4 ways to run something as the "current user", all of them have issues and can fail or end up running as the "wrong" non-admin user:

  • Use the token of the (hopefully) non-elevated parent, this is what the NSIS UAC plugin does.
  • Use the Windows Task Scheduler. This was a recommended practice in the early Vista days but I believe Microsoft has moved away from this method.
  • Use a shell COM object in the Explorer process that hosts the taskbar to call ShellExecute for you. The StdUtils plugin provides a ExecShellAsUser method that does this.
  • Use a Windows NT service. Because it runs as SYSTEM it can get the token handle of a user in any session.

If you decide that you still want to attempt to do this then you need to decide on your definition of current user before you choose a method.

Is it the user that logged in on the welcome screen? Is it the user the Explorer shell (Taskbar etc) is running as? Is it the parent process of your setup process? You should also keep in mind that runas.exe exists and a user might try to run something as a particular user for a reason...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM