blackadder has asked for the wisdom of the Perl Monks concerning the following question:
# Declare Libraries used use OLE; use Win32; use Getopt::Long; #use Win32::Perms; use Win32::NetAdmin; use Win32::AdminMisc; use Win32::FileSecurity qw ( MakeMask Set Get EnumerateRights); my $srv_lst; #Clear Screen system ( CLS ); sub configure { my ( $config ) = @_; Getopt::Long::Configure ( "prefix_pattern=(-|\/)" ); my $result = GetOptions ( $config, qw ( path|p=s help|?)); $config->{help}=1 if (! $result); } sub syntax { my( $script ) = (Win32::GetLongPathName( $0 ) =~ /([^\\\/]*?)$/ ); my( $line ) = "-" x length ( $script ); print <<EOT; $script $line User requested help Syntax: $script [ path to server list ] or [ No argument supplied for loca +l host ] [ path to server list ]........................path to servers lis +t [ Nothing ]....................................for local host only -help | -?......................................Display this help +message. Exampl $script c:\\my_dir\servers_list.txt <return> or $script <return> Note : path to the servers list can be remote of local. FOR FURTHER HELP CONTACT Tim) EOT } #Display used server list configure (\ my %config ); if ($config{help}) { syntax ( ); exit ( ); } if (! @ARGV) { print "\nLocal Host will be used\n"; my ($host ) = Win32::AdminMisc::GetComputerName ( ); push ( @srv_lst, $host ); } else { #Open server list file open ( LST, "@ARGV" ) || die "\n$! : @ARGV\n"; #Input server names into an array chomp ( @srv_lst = <LST> ); print "\n\nUsing server source '@ARGV'\n"; } Win32::MsgBox ( "Using server source @ARGV",32,"NT Server Access Contr +ol List" ); #Start Microsoft Excel, make it visible and add a workbook my $xls = CreateObject OLE "Excel.Application" || die "CreateObject: $ +!"; $xls -> { Visible } = 1; $xls -> Workbooks -> Add ( ); #Prepare Column width and title $xls -> Worksheets ( "Sheet1" ) -> Columns ( "A:A" ) -> { ColumnWidth +} =15; $xls -> Worksheets ( "Sheet1" ) -> Columns ( "B:B" ) -> { ColumnWidth +} =6; $xls -> Worksheets ( "Sheet1" ) -> Columns ( "C:C" ) -> { ColumnWidth +} =50; $xls -> Worksheets ( "Sheet1" ) -> Columns ( "D:D" ) -> { ColumnWidth +} =30; $xls -> Worksheets ( "Sheet1" ) -> Columns ( "E:E" ) -> { ColumnWidth +} =40; $xls -> Worksheets ( "Sheet1" ) -> Columns ( "F:F" ) -> { ColumnWidth +} =30; # Write the titles to Excel $xls -> Worksheets ( "Sheet1" ) -> Cells (1,1) -> Font -> { FontStyle +} = 'bold'; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,1) -> { Value } = "Server +Name"; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,2) -> Font -> { FontStyle +} = 'bold'; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,2) -> { Value } = "Drive"; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,3) -> Font -> { FontStyle +} = 'bold'; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,3) -> { Value } = "Directo +ry/Sub-Directory Scanned"; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,4) -> Font -> { FontStyle +} = 'bold'; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,4) -> { Value } = "Local G +roups"; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,5) -> Font -> { FontStyle +} = 'bold'; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,5) -> { Value } = "Users P +ermissioned"; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,6) -> Font -> { FontStyle +} = 'bold'; $xls -> Worksheets ( "Sheet1" ) -> Cells (1,6) -> { Value } = "Access +Type"; #Main program body - Go through each server in the array my $row = 2; foreach my $srv ( @srv_lst ) { my $col = 1; #Inform of what you are inttending to do print "\n\nObtaining drive information on server '$srv'\n"; $xls -> Worksheets ( "Sheet1" ) -> Cells ( $row, $col ) -> { Value + } = "$srv"; #Get server drives, and input drive letters into an array if ( Win32::NetAdmin::GetServerDisks ( "$srv", \ my @disks ) ) { foreach my $disk ( @disks ) { $col=2; next if $disk =~ /a|A|z|Z|c|C/; $disk =~ s/:/\$/; print"\nDrive $disk : "; $xls -> Worksheets ( "Sheet1" ) -> Cells ( $row, $col ) -> + { Value } = "$disk"; my $unc_path = "\\\\" . $srv . "\\" . $disk . "\\"; + my ( $size, $free ) = ( Win32::AdminMisc::GetDriveSpace ( +"$unc_path" ) ); if (Win32::AdminMisc::GetGroups("$srv", GROUP_TYPE_LOCAL, +\ @group )) { print "\nDone\n"; $col = 4; foreach $g (@group) { $xls -> Worksheets ( "Sheet1" ) -> Cells ( $row, $ +col) -> { Value } = "@group"; print "\n$g\n"; } } if ( $size != 0 ) { $col = 3; $size = int ( $size/1024/1024 ); $free = int ( $free/1024/1024 ); print "size = $size, Free = $free\n"; #Go through each drive and display directories and sub +-ditrectories only my $file_counter = 1; &print_dir ( "$unc_path"); sub print_dir { $col = 3; my ( $dir_name ) = @_; my ( $file, $sub_dir, $file_var ); $file_var = "CONST" . $file_counter++; opendir ( $file_var, $dir_name ) || die "\n$! : Ca +nnot Open Directory : '$dir_name'\n"; print "\n$dir_name :\n"; $xls -> Worksheets ( "Sheet1" ) -> Cells ( $row, $ +col ) -> { Value } = "$dir_name"; #The permissions check. foreach (@_) { next unless -e $_; if ( Get ( $_, \ %hash ) ) { while ( ( $name, $mask ) = each %hash ) { $col = 5; print "\n$name : \n \t "; + $xls -> Worksheets ( "Sheet1" ) -> Cel +ls ( $row, $col++ ) -> { Value } = "$name - ". &get_f_name; EnumerateRights ( $mask, \ @happy ); print join ( "\t\n" , @happy ), "\n"; $xls -> Worksheets ( "Sheet1" ) -> Cel +ls ( $row++, $col) -> { Value } = "@happy"; } } else { print ( "Error #", int ( $! ), " : $!" ); } } while ( $file = readdir ( $file_var ) ) { next if ( $file eq "." || $file eq ".." ); } rewinddir ( $file_var ); while ( $sub_dir = readdir ( $file_var ) ) { next unless ( -d ( $dir_name . "\\" . $sub_dir + ) ); next if ( $sub_dir eq "." || $sub_dir eq ".." +); &print_dir ( $dir_name . "\\". $sub_dir ); } closedir ( $file_var ); } } else { print "'CD-Rom Drive'\n"; #$xls -> Worksheets ( "Sheet1" ) -> Cells ( $row++, $c +ol ) -> { Value } = "$dir_name : CD-Rom Drive"; } } } } sub get_f_name { my $data = @_; my $usr = 'USER_FULL_NAME'; my %attrib = (); ($attrib{$usr}) if (Win32::AdminMisc::UserGetMiscAttributes("$unc_ +path",$name,\%attrib));
Edit kudra, 2002-06-10 Added readmore, removed double spacing
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Win32 ACLs: Local vs Global groups
by Util (Priest) on Jun 10, 2002 at 16:33 UTC | |
by blackadder (Hermit) on Jun 12, 2002 at 10:58 UTC | |
by blackadder (Hermit) on Jun 13, 2002 at 11:23 UTC |