How to make a file read-write to a program but read-only/no access to non-admin users in Windows?

半城伤御伤魂 提交于 2019-12-06 14:50:35
Harry Johnston

You'll need to split your code into two parts; the user interface, which runs in the user's context, and a service, which runs with admin privilege.

If you're programming in C, start with the MSDN library section on services for a general overview as well as the authoritative reference.

You'll probably want to use named pipes as the communication mechanism between the UI and the back end, although there are other options depending on your specific needs.

As an optimization once you've got it working, configure the service so that it only starts when the UI needs it. This answer shows how to configure a service so that any user can start it.

Applications don't have privileges, users do. The conditions "the program has full access to a particular file" and "the user has full access to a particular file" are indistinguishable, since a program runs with identical privileges as the user who started it.

So, in order for a program to run with higher privileges, it needs to run as a different user. You can do that by embedding an application manifest in your executable. Of course, then when you run it, you'll get a UAC prompt, and that cannot be bypassed.

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