如何在Windows中将文件读写为程序但对非管理员用户具有只读/无访问权限? [英] How to make a file read-write to a program but read-only/no access to non-admin users in Windows?

查看:62
本文介绍了如何在Windows中将文件读写为程序但对非管理员用户具有只读/无访问权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行以下操作:

  1. 非管理员用户可以在没有UAC提示的情况下运行我的程序.
  2. 该程序具有对特定文件的完全访问权限.
  3. 在程序之外,用户具有对该文件的只读或无访问权限.他们无法修改文件.他们只能通过程序对其进行修改.

有可能吗?

推荐答案

您需要将代码分成两部分;在用户上下文中运行的用户界面和以管理员权限运行的服务.

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.

如果您使用C语言进行编程,请从

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.

作为一项优化措施,一旦您可以使用它,请配置该服务,使其仅在UI需要时才启动. 此答案显示了如何配置服务,以便任何用户都可以启动该服务.

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.

这篇关于如何在Windows中将文件读写为程序但对非管理员用户具有只读/无访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆