Does anyone know why Cacls is successful where Win32::Perms fails???

I was not doing anything fancy, just removing user permission off a remote server. I was using Win32::Perms library and tried to remove the 'Everyone account' from that remote server (the server is located next door to where my desk is, and I do have Domain Admins rights to it). The script, after dumping account permission information on the screen, just hang forever (while I was chewing my nails to the bone and my boss was breathing hot and cold down my neck, by the way - I got this Job only 3 weeks ago).

I am not sure where I went wrong, maybe Perl is not the best tools to do this job!!?? Maybe I should have chosen another language, NT shell or VB script instead!!?? Maybe Win32::Perms doesn’t work as it was claimed to be!!?? Maybe there is no logic after all. But the whole thing is so very simple. This is what I did : first I get server name from the command line with this command “my $path = @ARGV;“, ensuring proper path was entered with correct number of slashes) and then applying the following command “my $result = system('cacls', $path, '/t', '/e', '/r', 'Everyone')”; the script tears through the server and removes the permissions as expected without any delays or problems. In contrast I used Win32::Perms in number of ways in my script, including some example code from Dave Roth’s first edition of Perl Win32 administration; None worked. Next, went and bought the second edition of his book (priced 59.4650 USD) and used the following example, by the way the PC that I am using is Windows 2000 Pro and the server is Windows 2000:

use Win32::Lanman; use Win32::Perms; use warnings; $! = $^E = 0; my %info; my ( $machine, $share_name ) = ( shift @ARGV || die ) =~ /^(\\\\.+?)\\ +(.*?)$/; if ( ! Win32::Lanman::NetShareGetInfo($machine, $share_name, \ %info ) + ) { print "Unable to retrieve information, $! : $^E.\n"; exit( ); } print "\n\nSuccessfully retrieved information\n\n"; my ( $perms_object ) = new Win32::Perms ( ) || die "\n\n$! : $^E\n\n"; $perms_object -> Import ( $info{security_descriptor}); $perms_object -> Dump; $perms_object -> Remove ('Everyone'); # HANGS HERE FOREVER $info{security_descriptor} = $perms_object -> GetSD ( SD_RELATIVE ); if ( ! Win32::Lanman::NetShareSetInfo($machine, $share_name, \ %info ) + ) { print "\n\nCompleted Successfully\n\n"; } else { print "\n\nUnable to set new Permissions\n\n"; my $status = Win32::Lanman::GetLastError(); print "\n\nError : ", Win32::FormatMessage( $status ); } $perms_object -> Close();
Guess what happened, exactly, it just hung (no errors or bleepso rattle and shake or smoke…etc, absolutely not a diddley). I do the same thing using Cacls and, hey Presto, it works.

Mr Monk “Particle” whom has helped me with this problem commented that it is a bit of an over kill to use Win32::Perms library if removing Permissions from dir/sub-dirs was the only thing I was doing, True, but there again, Why not use this library then??, why was this library produced ?? What is the threshold of number of NT permission commands used in any script before it warrants using this library??

CAN SOMEONE THROUGH SOME LIGHT ON THIS PLEASE, AND RESTORE MY FAITH?

Edit by tye


In reply to Win32::Perms failes where Cacls doesn't by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.