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

Hi Perl Monks

We have some code that has been working fine under Windows NT/XP but does not work on Windows 7. We are using Perl 5.6.1, and yes I know that using Perl 5.8 might be better as well as anything besides Windows for an OS, but we have a few million lines of Perl code running on several thousand machines around the world, so porting is difficult. Any help or insight that you could provide would be appreciated.

The following code is used to check permissions on a shared directory. It works from an XP system to a W7 system ie using path \\windows7\public, it works from XP to XP and XP to self, but if I use the same path on \\windows7 it fails to retrieve the security information.

my $GetFileSecurity = new Win32::API('Advapi32', 'GetFileSecurity', ['P', 'N', 'P', 'N', 'P'], 'N' ); sub GetFileSecurity { my $file = shift; my $bufSize = 1000; my $bufSD = pack("x$bufSize"); my $pbufNeeded = pack('x4'); my $strSD = ''; foreach my $infoRequest (1,2,4,8) { my $sd; if ($GetFileSecurity->Call($file, $infoRequest, $bufSD, $bufSize +, $pbufNeeded) ) { my $size = unpack('L', $pbufNeeded); my $binSD = substr($bufSD,0, $size); $strSD .= SD2Str($binSD); } } return $strSD; } my $ConvertSDToString = new Win32::API('Advapi32', 'ConvertSecurityDescriptorToStringSecur +ityDescriptor', ['P', 'N', 'N', 'P', 'P'], 'N' ); sub SD2Str { my $SD = shift; return undef if (!IsValidSD($SD)); my $rev = 1; my $info = 7; my $p1 = ' '; my $len = ' '; return '' if ( !$ConvertSDToString->Call($SD, $rev, $info, $p1, $le +n) ); my $str = unpack('p', $p1); return $str; }

Your help is greatly appreciated, thanks - Rick

Replies are listed 'Best First'.
Re: Calling Win32::API GetFileSecurity not working on Windows 7
by Illuminatus (Curate) on Sep 29, 2009 at 22:06 UTC
    They may have moved GetFileSecurity from advapi32.dll to kernelbase.dll see here. This may or may not make a difference, since it is supposed to re-direct. Microsoft makes it pretty clear that stuff that works on Vista should work OK on Win7, but nothing about XP-to-Win7...

      Thanks for your help, I suspected this might be an issue. I'll have a look down that path.

Re: Calling Win32::API GetFileSecurity not working on Windows 7
by Anonymous Monk on Sep 30, 2009 at 04:47 UTC
    Why aren't you doing any error checking?

      Not sure. I inherited this code from another author, so I'm not quite sure if negative conditions could be ignored or if in fact they should throw an error. I'm going to see if I can get the same information I need from Win32::Perms from some code in Dave Roth's Perl Scripting book. Thanks - Rick