Start program with user rights from within a elevated program

﹥>﹥吖頭↗ 提交于 2019-12-11 04:34:53

问题


I have an application that requires elevated rights (it is something like a custom installer). From within this application, I use ShellExecute() to show a PDF file. It seems as if the Adobe Reader is started with the same rights as the calling application. I would like the Adobe Reader however to be started with standard user rights and not elevated.

Is there some way I can do that? (It would be in Delphi, but for this problem the language probably doesn't matter).


回答1:


There's no really straightforward way to do this unfortunately.

One way you can do it is with Task Scheduler - you use the ITaskService interface to schedule a task to run immediately, using the non-elevated credentials of the currently logged in user.




回答2:


What you are trying to achieve cannot be done very easily and is not supported. However, it is possible using a modicum of hacking. Aaron Margosis wrote an article describing one technique.

To quote the pertinent section, you will need to carry out these steps:

  1. Enable the SeIncreaseQuotaPrivilege in your current token
  2. Get an HWND representing the desktop shell (GetShellWindow)
  3. Get the Process ID (PID) of the process associated with that window (GetWindowThreadProcessId)
  4. Open that process (OpenProcess)
  5. Get the access token from that process (OpenProcessToken)
  6. Make a primary token with that token (DuplicateTokenEx)
  7. Start the new process with that primary token (CreateProcessWithTokenW)

The article contains a download link for some demo C++ source from which it should be simple enough to translate to Delphi.



来源:https://stackoverflow.com/questions/17152790/start-program-with-user-rights-from-within-a-elevated-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!