我使用的ActiveState Perl的Windows Server 2003的如何修改Perl中的Windows NTFS權限?
我想創建一個Windows NTFS分區上的目錄,然後授予Windows NT安全組讀訪問該文件夾上。這在Perl中可能嗎?我必須使用Windows NT命令還是有一個Perl模塊來執行它?
一個小例子將不勝感激!
我使用的ActiveState Perl的Windows Server 2003的如何修改Perl中的Windows NTFS權限?
我想創建一個Windows NTFS分區上的目錄,然後授予Windows NT安全組讀訪問該文件夾上。這在Perl中可能嗎?我必須使用Windows NT命令還是有一個Perl模塊來執行它?
一個小例子將不勝感激!
的標準方法是使用Win32::FileSecurity模塊:
use Win32::FileSecurity qw(Set MakeMask);
my $dir = 'c:/newdir';
mkdir $dir or die $!;
Set($dir, { 'Power Users'
=> MakeMask(qw(READ GENERIC_READ GENERIC_EXECUTE)) });
注意Set
將覆蓋該目錄的權限。如果你想編輯現有的權限,你需要首先使用Get
:
my %permissions;
Win32::FileSecurity::Get($dir, \%permissions);
$permissions{'Power Users'}
= MakeMask(qw(READ GENERIC_READ GENERIC_EXECUTE)) });
Win32::FileSecurity::Set($dir, \%permissions);
Here是ActivePerl的通用權限包。
use Win32::Perms;
# Create a new Security Descriptor and auto import permissions
# from the directory
$Dir = new Win32::Perms('c:/temp') || die;
# One of three ways to remove an ACE
$Dir->Remove('guest');
# Deny access for all attributes (deny read, deny write, etc)
$Dir->Deny('joel', FULL);
# Set the directory permissions (no need to specify the
# path since the object was created with it)
$Dir->Set();
# If you are curious about the contents of the SD
# dump the contents to STDOUT $Dir->Dump;