简体   繁体   English

需要Windows chmod777等效

[英]Need Windows chmod777 Equivalent

I need to set permissions on a file, so that all users on the system can read and write to it. 我需要为文件设置权限,以便系统上的所有用户都可以读取和写入文件。 This is related to an installer, so I do not know the user names ahead of time. 这与安装程序有关,因此我不知道用户名。 The installer runs as admin, so the log file requires admin access afterwards. 安装程序以管理员身份运行,因此日志文件之后需要管理员访问权限。 So I need to explicitly set the permissions, during the install, so that referencing programs don't need to be run as admin. 因此,我需要在安装期间明确设置权限,以便引用程序不需要以管理员身份运行。

In essence, I'm looking for a solution that can give me the equivalent of chmod777 in Windows. 从本质上讲,我正在寻找一种能够在Windows中为我提供相当于chmod777的解决方案。

I would prefer a solution that works for both Win7 and WinXP. 我更喜欢适用于Win7和WinXP的解决方案。 I would like a solution that is through command line, which I can then script. 我想要一个通过命令行的解决方案,然后我可以编写脚本。 Or a solution using C# or java. 或者使用C#或java的解决方案。

All modern Windows OS's have a build-in group called "Everyone" that is the equivalent of the UNIX "other" permissions. 所有现代Windows操作系统都有一个名为“Everyone”的内置组,它相当于UNIX“其他”权限。 Even non-logged-in users are part of the Everyone group. 即使未登录的用户也是Everyone组的一部分。 From there you can give "Everyone" read, write, and modify ("change") permissions. 从那里你可以给“Everyone”读取,写入和修改(“更改”)权限。 You could, if you were completely insane, give Everyone "full control" but that actually allows them to take ownership and change the permissions, so please don't do that :) 你可以,如果你是完全疯了,给每个人“完全控制”但实际上允许他们取得所有权并更改权限,所以不要这样做:)

To actually apply these permissions you can use a number of techniques 要实际应用这些权限,您可以使用许多技术

In C#, you can get an NTAccount object, and get the file's FileSecurity object, and use the FileSecurity object's AddAccessRule method to set permissions. 在C#中,您可以获取NTAccount对象,并获取文件的FileSecurity对象,并使用FileSecurity对象的AddAccessRule方法来设置权限。

See the MSDN forum post below for more detailed instructions. 有关更多详细说明,请参阅下面的MSDN论坛帖子。

http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/c513ca26-9bf8-4e39-a993-4ebf90aaece6/ http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/c513ca26-9bf8-4e39-a993-4ebf90aaece6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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