blackadder has asked for the wisdom of the Perl Monks concerning the following question:

Greetings

This is a quick one:

I have the following code which grants group full access permission to directory level and all files and folders below this directory.

The code works fine in W2K environment, however, it doesn’t in WinNT 4.

Any ‘Perls of wisdom, Please’ on how to convert and get this code to work with WinNT4.

Many Thanks
Use Win32::Perms; sub AddGroupToDir { my ($group, $dir)=@_; my $perms = new Win32::Perms($dir) || die "\n$^E\n"; my $counter = $perms->Get(\ my @list); print "\nAccount '$group'\t Path " . $perms->Path() . "\n"; $perms->Add("$group", FULL|FULL, ACCESS_ALLOWED_ACE_TYPE, OBJECT_I +NHERIT_ACE | CONTAINER_INHERIT_ACE); if ($perms->Set()) { Win32::MsgBox("Account: '$group' was garanted Full ACE permiss +ion to: '". $perms->Path() . "'",0x00000000|0x00000040|0x00000000,"Op +eration Successful"); } else { Win32::MsgBox("This particular operation has failed\n\n***PLEA +SE CONTACT THE ADMINISTRATOR***\n",0x00000000|0x00000040|0x00000000," +Operation Failure"); } $perms->Close(); }

Replies are listed 'Best First'.
Re: Perms under WinNT4
by Necos (Friar) on Aug 12, 2002 at 20:36 UTC
    While the thought is still fresh in my head... Please, use Win32::FileSecurity. It's much easier to use than Win32::Perms and does the exact same thing. Not only that, but it provides a MakeMask function that will convert an or'd group of attributes into a bitmask. It comes in very handy. Also, Win32::FileSecurity works on directories that are accessed via sharepoints (something that Win32::Perms cannot).

    I will post an update with a snippet of code when I get to my office.

    Theodore Charles III
    Network Administrator
    Los Angeles Senior High
    4650 W. Olympic Blvd.
    Los Angeles, CA 90019
    323-937-3210 ext. 224
    email->secon_kun@hotmail.com
    perl -e "map{print++$_}split//,Mdbnr;"
Re: Perms under WinNT4
by BrowserUk (Patriarch) on Aug 12, 2002 at 18:09 UTC

    Your code (slightly modified in a non-significant way) works fine on my NT4 box as

    #! perl -w use Win32::Perms; sub AddGroupToDir { my ($group, $dir)=@_; my $perms = new Win32::Perms($dir) || die "\n$^E\n"; my $counter = $perms->Get(\ my @list); print "\nAccount '$group'\t Path " . $perms->Path() . "\n"; $perms->Add("$group", FULL|FULL, ACCESS_ALLOWED_ACE_TYPE, OBJECT_I +NHERIT_ACE | CONTAINER_INHERIT_ACE); if ($perms->Set()) { print "Account: '$group' was granted Full ACE permission to: ' +". $perms->Path() . "'", 0x00000000|0x00000040|0x00000000,"' Operation Successful"; } else { print "This particular operation has failed\n\n***PLEASE CONTA +CT THE ADMINISTRATOR***\n", 0x00000000|0x00000040|0x00000000,"Operation Failure"; } $perms->Close(); } AddGroupToDir( 'ALL', 'D:/TEMP' ); __END__ C:\test>189474 Account 'ALL' Path D:\TEMP Account: 'ALL' was granted Full ACE permission to: 'D:\TEMP'64' Operat +ion Successful C:\test>

    I ran it whilst logged on as Administrator.

    My first guess is that the account you are running it under doesn't have permission to set or modify the permissions on the object you are modifying?

      I have found out the hard way that my account is not privileged enough. Also I am getting progressively convinced that the Perms library has caused me more aggro than good.

      Thank you very much for all you help and guidance.