Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I would prefer a solution that works for both Win7 and WinXP. I would like a solution that is through command line, which I can then script. Or a solution using C# or java.

like image 998
James Oravec Avatar asked Apr 19 '26 20:04

James Oravec


1 Answers

All modern Windows OS's have a build-in group called "Everyone" that is the equivalent of the UNIX "other" permissions. Even non-logged-in users are part of the Everyone group. From there you can give "Everyone" read, write, and modify ("change") permissions. 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

  • From a command-line, you can run cacls <file name> /g Everyone:RWC
  • In .NET you can create an ACL for the NT Account with WellKnownSidType.WorldSid then apply it to a file, as in this article: http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/c513ca26-9bf8-4e39-a993-4ebf90aaece6/
  • You can use WMI, as per How to change file permissions with WMI? (should work in any WMI-enabled language)
  • You could use the native Win32 file permission APIs (via P/Invoke or JNI).
like image 71
Michael Edenfield Avatar answered Apr 21 '26 09:04

Michael Edenfield



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!