Mar*_*son 5 permissions perl winapi
我在Windows Server 2003上使用ActiveState Perl.
我想在Windows NTFS分区上创建一个目录,然后授予Windows NT安全组对该文件夹的读取权限.在Perl中这可能吗?我是否必须使用Windows NT命令或是否有Perl模块来执行此操作?
一个小例子将非常感谢!
cjm*_*cjm 10
标准方法是使用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 ) ) });
Run Code Online (Sandbox Code Playgroud)
请注意,Set它将覆盖该目录的权限.如果要编辑现有权限,首先需要Get它们:
my %permissions;
Win32::FileSecurity::Get($dir, \%permissions);
$permissions{'Power Users'}
= MakeMask( qw( READ GENERIC_READ GENERIC_EXECUTE ) ) });
Win32::FileSecurity::Set($dir, \%permissions);
Run Code Online (Sandbox Code Playgroud)
这是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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3455 次 |
| 最近记录: |