Link to home
Start Free TrialLog in
Avatar of Vendi
Vendi

asked on

File Permissions Example

Does anyone have an example of setting individual file permissions?  Adding and removing users, etc?  Or an example of accessing a machine from the network?

For example, we have Windows 2000 pro clients, windows 2000 server and we want to run a process on the server that changes the permissions on the file c:\xyz.xxx from read only to full access or only add write permissions for users on that machine.
Avatar of Madshi
Madshi

You can't change permissions on a per-file-base, you can only change permissions on directory base.
You must differ between share permissions and security permissions. If you right click on a NTFS-directory or on a drive, you get the two tabs (beside others) "Share" and "Security". The first one holds the permissions for remote pcs, while the second hols permissions for local users.
You can use Get/SetFileSecurity to change the security stuff. And you can use Get/SetSecurityInfo and Get/SetNamedSecurityInfo to change both the security or the share permissions.

If you want to have it easy, look at my package "madSecurity" (free for non-commercial usage). With it you can do something like this:

  FileSecurity('C:\Folder').DAcl.SetFileAccess(CurrentUser, true);
  // add write access for the current user to the security permissions of "C:\Folder"

  Share('shareName').Acl.SetFileAccess(CurrentUser, false);
  // add read access for the current user to the share permissions

Regards, Madshi.
Avatar of Vendi

ASKER

Well, I really need a per file solution.  I'm looking into windows scripting solutions now and think I've found what I need.  I'll delete this question unless someone comes up with a per file solution.

Setting directory only permissions isn't going to work because we are trying to prevent users from accessing the C:\winnt directory.  Unfortunately, there are a couple of files there that Wordperfect needs the user to have additional permissions on or it won't print.  Thanks for trying though.
care to tell us your solution, Vendi?
Avatar of Vendi

ASKER

http://msdn.microsoft.com/workshop/languages/clinic/scripting06122000.asp

This url is about a script to add users, accounts, everything.  But part of this script contains a function called AddRights.  I'm trying to modify it to work on a file like:  \\machine\c$\file.xxx from a server.  I could modify the individual file permissions on my local machine and now I need to work on the network part.  (Monday, LOL!)

I'm still interested in the Delphi (or C++ Builder) solution.  But it has to be per file.  I started looking at some of the GetACL or the like functions but I got lost really fast!  :(
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vendi

ASKER

Okay, Madshi, I'll take a look at your site!  Thanks for looking into that.  This is so new to me, I need all the help I can get.  It may take me a week or two to get comfortable with it but I won't abandon the question.  Thanks again!  :)
Avatar of Vendi

ASKER

I haven't tried it out yet.  (no time, once we figured out the WSH solution, other stuff came up as usual)  Thanks for your comments.
Okay, thanx for the points...   :-)