blackadder has asked for the wisdom of the Perl Monks concerning the following question:
use Tk; use Win32; use strict 'vars'; use Win32::Perms; my $main = MainWindow->new; my (@pl) = qw/-side left -expand yes -padx 10 -pady 10 -fill both/; my $left = $main->Frame->pack(@pl); my $right = $main->Frame->pack(@pl); @pl = qw/-side top -expand yes -pady 2 -anchor w/; my $left_l1 = $left->Label(-text=>'Path')->pack(@pl); my $left_l2 = $left->Label(-text=>'Account')->pack(@pl); @pl=qw/-side top/; my $r_entry1 = $right->Entry(-width=>40, -textvariable=> \ my $path)-> +pack(@pl); my $r_entry2 = $right->Entry(-width=>40, -textvariable=> \ my $acc)->p +ack(@pl); @pl = qw/-side bottom -padx 5 -pady 5/; my $buttn1 = $left->Button(-text=>'Addition', -borderwidth=>5, -width= +>10, -command=>sub { syntax( ) if (($path eq "")||($acc eq "")); print "\n\nScript operation is perms addition\n\n" +; my $prms = new Win32::Perms($path) || die "$^E\n"; print "\nAccount '$acc' Path: " . $prms->Path() . +"\n"; if ($prms->Add("$acc", FULL|FULL, ACCESS_ALLOWED_A +CE_TYPE, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE)) { $prms->SetRecurse($path); $prms->Set( ); $prms->Dump; print "\nSuccessfully added '$acc' FULL access + permission to '$path'\n"; Win32::MsgBox("Addition operation completed su +ccessfully",32,"Perms"); } exit( ); } )->pack(@pl); my $buttn2 = $right->Button(-text=>'Remove', -borderwidth=>5, -width=> +10, -command=>sub { syntax( ) if (($path eq "")||($acc eq "")); my $prms = new Win32::Perms($path) || die "$^E\n"; my $indx = $prms->Get(\ my @prms_list); print "\nPath " . $prms->Path( ) . "\n"; print "\nRemove account '$acc' ACE permissions fro +m path '$path'\n"; print "\nNumber of indexes: '$indx'\n"; while ($indx--) { my $rec_ref = $prms_list[$indx]; foreach my $entry (keys %$rec_ref) { next unless ($entry =~ /account/i ); if ($rec_ref->{$entry} =~ /$acc/i ) { print": Distruct '$indx $rec_ref->{$en +try}'\n"; $prms->Remove( $indx ); $prms->SetRecurse($path); if ($prms->Set( )) { print "Successfully removed permis +sions\n"; Win32::MsgBox("Remove operation co +mpleted successfully",32,"Perms"); } else { print "\nFailed to remove $indx: $ +acc\n"; } } else { print "\n\n"; } } } exit( ); } )->pack(@pl); MainLoop; sub syntax { my ( $script ) = $0; my ( $line ) = "-" x length ( $script ); system (CLS); Win32::MsgBox("$script\n$line\n\tSyntax\nNo command line syntax av +ailable.\n However a valid path and account name must be supplied. +". "\nExample\npath\n\t\\\\remote_srv\\share_name or drive letter\nAc +count\n\tdomain admins or user",32,"Perms"); print <<EOT; User requested help or invalid operating option(s) were detected. $script $line Syntax No command line syntax available. However a valid path and account name must be supplied. Example path \\\\remote_srv\\share_name or drive letter Account domain admins or user1 Path............UNC Directory or Share path, can be remote or +local. Such as:\\\\remote_server\\Drive_letter or \\\\remote_server\\Share_name or local drive letter. Account.........Valid group or user name is required. Two part account name must be within "". Such as "domain admins" Operation.......[r]emove or [a]dd permissions Adding permissions, ONLY local groups are allowed (no users or Glo +bal Groups). for further information contact IT support on ext: 3607 EOT exit( ); }
|
|---|