2023年12月6日发(作者:)
如何使用 修改 NTFS 权限
分步指南介绍如何使用扩展的更改访问控制列表工具 () 修改和查看文件或文件夹的
NTFS 权限。
使用 可以通过命令行设置所有可在 Windows 资源管理器中访问到的文件系统安全选项。 通过显示和修改文件的访问控制列表 (ACL) 完成此操作。
在 Windows 2000 Professional 或 Windows 2000 Server 的无值守安装中特别有用。通过使用此工具,可以为操作系统所在的文件夹设置初始访问权限。在您将软件分发到服务器或工作站时, 还提供单步保护,以防止用户删除文件夹或文件。
实用工具包含在 Windows 2000 资源工具包 中。 可以从 Microsoft 下载中心下载以下文件:
立即下载 XCacls_ 软件包。
语法
xcacls 文件名 [/T] [/E] [/C] [/G user:perm;spec] [/R 用户] [/P user:perm;spec [...]]
[/D 用户 [...]] [/Y]
其中文件名表示 ACL 或访问控制项 (ACE) 通常应用于的文件或文件夹的名称。所有标准通配符均可使用。
/T 递归检查当前文件夹及其所有子文件夹,对匹配的文件或文件夹应用所选的访问权限。
/E 编辑 ACL 而不替换它。例如,如果您运行 XCACLS /G Administrator:F 命令,则只有管理员拥有对 文件的访问权限。之前应用的所有 ACE 都会丢失。
/C 使 在出现“拒绝访问”错误消息时继续执行。如果未指定 /C,则 在出现此错误时停止执行。
/G user:perm;spec 授予用户对匹配文件或文件夹的访问权限。
perm(权限)变量对文件应用指定的访问权限,并代表文件夹的特殊文件访问权限掩码。perm 变量接受下列值:
o R 读取
o C 更改(写入)
o F 完全控制
o P 更改权限(特殊访问权限) o O 取得所有权(特殊访问权限)
o X 执行(特殊访问权限)
o E 读取(特殊访问权限)
o W 写入(特殊访问权限)
o D 删除(特殊访问权限)
spec(特殊访问权限)变量仅应用于文件夹,它除了接受与 perm 相同的值以外,还接受以下特殊值:
o T 未指定。为目录本身设置 ACE,而不指定应用于在该目录中创建的新文件的
ACE。至少存在一个要遵循的访问权限。分号 (;) 和 T 之间的项将被忽略。注意:
文件的访问权限选项(针对文件夹、特殊文件和文件夹访问)是完全相同的。有关这些选项的详细说明,请参阅 Windows 2000 操作系统的文档。
所有其他选项(它们也可以在 Windows 资源管理器中设置)都是基本访问权限的所有可能组合的子集。因此,不存在文件夹访问权限(如 LIST 或
READ)的特殊选项。
/R 用户为指定用户调用所有访问权限。
/P user:perm;spec 替换用户的访问权限。指定 perm 和 spec 的规则与 /G 选项相同。请参阅本文的“ 示例”部分。
/D 用户拒绝用户访问文件或目录。
/Y 禁止在替换用户访问权限时出现确认提示。默认情况下,CACLS 要求确认。由于存在此功能,在批处理例程中使用 CACLS 时,例程将停止响应并等待输入正确答案。引入 /Y 选项后可消除此确认,从而可以在批处理模式下使用 。
回到顶端
使用 查看权限
还可用于查看文件或文件夹的权限。例如,在命令提示符处键入 xcacls
C:winnt,然后按 Enter。下面是典型结果:
c:WINNT BUILTINUsers:R
BUILTINUsers:(OI)(CI)(IO)(special access:)
GENERIC_READ
GENERIC_EXECUTE
BUILTINPower Users:C
BUILTINPower Users:(OI)(CI)(IO)C
BUILTINAdministrators:F BUILTINAdministrators:(OI)(CI)(IO)F
NT AUTHORITYSYSTEM:F
NT AUTHORITYSYSTEM:(OI)(CI)(IO)F
BUILTINAdministrators:F
CREATOR OWNER:(OI)(CI)(IO)F
这些 ACL 标志具有下列含义:
IO:仅继承 — 此标志表示此 ACE 不应用于当前对象。
CI:容器继承 — 此标志表示从属容器将继承此 ACE。
OI:对象继承 — 此标志表示从属文件将继承该 ACE。
NP:不传播 — 此标志表示从属对象不继续传播继承的 ACE。
每行末尾的字母表示权限。例如:
F:完全控制
C:更改
W:写入
回到顶端
示例
示例 1
在命令提示符下键入 XCACLS *.* /G administrator:RW /Y,然后按 Enter 以替换当前文件夹中所有文件和文件夹的 ACL,而不扫描子文件夹且不进行确认。
示例 2
在本示例中,添加到文件夹的 ACE 还将继承在此文件夹中创建的新文件的 ACE。该命令授予
TestUser 对此文件夹中的所有新建文件的读取、写入、运行和删除权限,但只授予对文件夹本身的读写权限。在命令提示符下键入 XCACLS *.* /G TestUser:RWED;RW /E,然后按 Enter。
示例 3
下面的示例将授予对文件夹的读写权限,而不为新文件创建继承项。因此,在本示例中,此文件夹中的新建文件不会收到 TestUser 的 ACE。对于现有文件,将创建具有读取权限的 ACE。在命令提示符下键入 XCACLS *.* /G TestUser:R;RW /E,然后按 Enter。
回到顶端
NTFS 权限原则
下面是分配 NTFS 权限的原则:
使用 NTFS 权限控制对文件和文件夹的访问。
将权限分配给组而不是单独用户。
NTFS 文件权限优先于 NTFS 文件夹权限。
管理员以及文件或文件夹的所有者控制可为该对象设置的权限。
在更改文件夹权限时,应了解服务器上安装的程序。程序会创建自己的文件夹并打开“允许从父系来的继承权限传播到这个对象”设置。如果更改了父文件夹中的权限,则这些更改可能会导致程序中出现问题。
警告:请记住,许多文件和文件夹通过继承接收权限。因此,在您认为只是更改了一个文件夹时,您可能更改了其他更多内容。
如何使用 修改 NTFS 权限
Microsoft 以 Microsoft Visual Basic 脚本 () 的形式提供了 Extended Change
Access Control List(扩展更改访问控制列表)工具 () 的更新版本。本文分步介绍如何使用 脚本修改和查看文件或文件夹的 NTFS 文件系统权限。 可以从命令行使用
设置所有可在 Microsoft Windows 资源管理器中访问的文件系统安全选项。 可显示和修改文件的访问控制列表 (ACL)。
注意: 只与 Microsoft Windows 2000、Microsoft Windows XP 和 Microsoft
Windows Server 2003 兼容。Microsoft 不支持 。
设置和使用
要设置和使用 ,请按照下列步骤操作:
1. 从以下 Microsoft 网站获得 的最新版本:
/download/f/7/8/f786aaf3-a37b-45ab-b0a2-8c8c18bbf483/XCacls_
2. 双击“Xcacls_”。当提示您提供放置提取文件的位置时,请指定一个位于计算机的搜索路径设置中的文件夹(如 C:Windows)。
3. 将默认脚本引擎从 Wscript 更改为 Cscript。( 脚本最适合在 Cscript 下运行。)为此,请在命令提示符下键入以下内容,然后按 Enter: /h:cscript
注意:将默认脚本引擎更改为 Cscript 只影响脚本向屏幕写入的方式。Wscript 根据“确定”对话框分别写入每一行。Cscript 将每一行写入命令窗口。如果您不想更改默认脚本引擎,则必须使用以下命令运行脚本
但是,如果将默认脚本更改为 Cscript,则可以使用以下命令运行该脚本:
.
4. 要查看 的命令语法,请在命令提示符处键入下面的命令:
/?
命令的语法
下面 /? 命令的输出描述了 命令的语法:
Usage:
XCACLS filename [/E] [/G user:perm;spec] [...] [/R user [...]]
[/F] [/S] [/T]
[/P user:perm;spec [...]] [/D user:perm;spec]
[...]
[/O user] [/I ENABLE/COPY/REMOVE] [/N
[/L filename] [/Q] [/DEBUG]
filename [Required] If used alone, it displays
ACLs.
(Filename can be a filename, directory
name or
wildcard characters and can include the
whole
path. If path is missing, it is assumed
to be
under the current directory.)
Notes:
- Put filename in quotes if it has spaces
or special characters such as &, $, #, etc.
- If filename is a directory, all files
and
subdirectories under it will NOT be
changed
unless the /F or S is present.
/F [Used with Directory or Wildcard] This
will change all
files under the inputted directory but
will NOT
traverse subdirectories unless /T is also
present.
If filename is a directory, and /F is not
used, no
files will be touched.
/S [Used with Directory or Wildcard] This
will change all
subfolders under the inputted directory
but will NOT
traverse subdirectories unless /T is also
present.
If filename is a directory, and /S is not
used, no
subdirectories will be touched.
/T [Used only with a Directory] Traverses
each
subdirectory and makes the same changes.
This switch will traverse directories
only if the
filename is a directory or is using
wildcard characters.
/E Edit ACL instead of replacing it.
/G user:GUI Grant security permissions similar to
Windows GUI standard (non-advanced) choices.
/G user:Perm;Spec Grant specified user access rights.
(/G adds to existing rights for user)
User: If User has spaces in it, enclose
it in quotes.
If User contains #machine#, it will
replace
#machine# with the actual machine
name if it is a
non-domain controller, and replace
it with the
actual domain name if it is a domain
controller.
New to 3.0: User can be a string
representing
the actual SID, but MUST be lead by
SID#
Example:
(SID string shown has been
shortened)
(If any user has SID# then
globally all
matches must match the SID
(not name)
so if your intention is to
apply changes
to all accounts that match
DomainUser
then do not specify SID# as
one of the
users.)
GUI: Is for standard rights and can be:
F Full control M Modify
X read and eXecute
L List folder contents
R Read
W Write
Note: If a ; is present, this will
be considered
a Perm;Spec parameter pair.
Perm: Is for "Files Only" and can be:
F Full control
M Modify
X read and eXecute
R Read
W Write
D Take Ownership
C Change Permissions
B Read Permissions
A Delete
9 Write Attributes
8 Read Attributes
7 Delete Subfolders and
Files
6 Traverse Folder / Execute
File
5 Write Extended Attributes
4 Read Extended Attributes
3 Create Folders / Append
Data
2 Create Files / Write Data
1 List Folder / Read Data
Spec
and has the
same choices as Perm.
/R user Revoke specified user's access rights.
is for "Folder and Subfolders only" (Will remove any Allowed or Denied ACL's
for user.)
/P user:GUI Replace security permissions similar to
standard choices.
/P user:perm;spec Replace specified user's access
rights.
For access right specification see /G
option.
(/P behaves like /G if there are no rights
set for user.)
/D user:GUI Deny security permissions similar to
standard choices.
/D user:perm;spec Deny specified user access rights.
For access right specification see /G
option.
(/D adds to existing rights for user.)
/O user Change the Ownership to this user or
group.
/I switch Inheritance flag. If omitted, the
default is to not touch
Inherited ACL's. Switch can be:
ENABLE - This will turn on the
Inheritance flag if
it is not on already.
COPY - This will turn off the
Inheritance flag and
copy the Inherited ACL's
into Effective ACL's.
REMOVE - This will turn off the
Inheritance flag and
will not copy the Inherited
ACL's. This is the opposite of
ENABLE. If switch is not present, /I will be
ignored and
Inherited ACL's will remain untouched.
/L filename Filename for Logging. This can include
a path name
if the file is not under the current
directory.
File will be appended to, or created if
it does not
exit. Must be Text file if it exists or
error will occur.
If filename is omitted, the default name
of XCACLS will
be used.
/Q Turn on Quiet mode. By default, it is
off.
If it is turned on, there will be no
display to the screen.
/DEBUG Turn on Debug mode. By default, it is off.
If it is turned on, there will be more
information
displayed and/or logged. Information
will show
Sub/Function Enter and Exit as well as
other important
information.
/SERVER servername Enter a remote server to run script
against.
/USER username Enter Username to impersonate for
Remote Connections (requires PASS switch). Will be
ignored if it is for a Local Connection.
/PASS password Enter Password to go with USER switch
(requires USER switch).
Wildcard characters can be used to specify more than one file
in a command, such as:
* Any string of zero or more
characters
? Any single character
You can specify more than one user in a command.
You can combine access rights.
使用 查看权限
还可用于查看文件或文件夹的权限。 例如,如果您有一个名为 C:Test 的文件夹,在命令提示符处键入以下命令以查看文件夹权限,然后按 Enter:
c:test
下面的示例是一个典型结果:
C:> c:test
Microsoft (R) Windows Script Host 5.6
版权所有 (C) Microsoft Corporation 1996-2001。保留所有权利。
Starting (Version: 3.4) Script at 6/11/2003
10:55:21 AM
Startup directory:
"C:test"
Arguments Used:
Filename = "c:test"
**************************************************************************
Directory:C:test
Permissions:
Type Username Permissions
Inheritance
Allowed BUILTINAdministrators Full Control This
Folder, Subfolde
Allowed NT AUTHORITYSYSTEM Full Control This
Folder, Subfolde
Allowed Domain1User1 Full Control This
Folder Only
Allowed CREATOR OWNER Special (Unknown)
Subfolders and Files
Allowed BUILTINUsers Read and Execute This
Folder, Subfolde
Allowed BUILTINUsers Create Folders / Appe This
Folder and Subfo
Allowed BUILTINUsers Create Files / Write This
Folder and Subfo
No Auditing set
Owner:Domain1User1
注意:在该示例中, c:test 命令的输出与显示在图形用户界面 (GUI) 的文本一致。命令窗口的一些文字不完整。
输出还给出了脚本的版本、启动目录和使用的参数。
您还可以使用通配符来显示目录下匹配的文件。例如,如果键入以下命令,将会显示 C:Test 文件夹中所有具有“.log”扩展名的文件:
c:test*.log 示例
下列 命令提供 用法的一些示例:
c:test /g domaintestuser1:f /f /t /e
该命令可编辑现有权限。它授予 DomainTestUser1 完全控制 C:Test 下所有文件的权限,遍历
C:Test 下的子文件夹,然后更改找到的所有文件。该命令不触及目录。
c:test /g domaintestuser1:f /s /l "c:"
该命令可替换现有权限。它授予 DomainTestUser1 完全控制 C:Test 下所有子文件夹的权限,而且记录到 C:。该命令不触及文件,并且不遍历目录。
c: /o "machineagroup1"
该命令将自述文件的所有者更改为组 MachineAGroup1。
c: /r "machineagroup1" /r "domaintestuser1"
该命令撤消 MachineAGroup1 和 DomainTestUser1 的 C: 权限。
c:testsubdir1 /i enable /q
该命令将打开文件夹 C:TestSubdir1 上的继承。该命令将取消任何屏幕输出。
/p "domaingroup2":14
此命令通过使用 Windows Management Instrumentation (WMI) 远程连接到
ServerAShareZ。然后获取用于该共享的本地路径,在该路径下,它更改 上的权限。它原封保留 DomainGroup2 的现有权限,但是添加权限 1(读取数据)和权限 4(读取扩展属性)。该命令放弃此文件上的其他权限,原因是未使用 /e 开关。
d: /g "domaingroup2":f /server servera /user
serveraadmin /pass password /e
该命令使用 WMI 作为 ServerAAdmin 远程连接到 ServerA,然后将 上的完全权限授予 DomainGroup2。DomainGroup2 的现有权限丢失,但保留文件上的其他权限。


发布评论