文件夹权限的批量修改

文件夹权限的批量修改
文件夹权限的批量修改

如何使用Xcacls.exe 修改NTFS 权限

本页

?概要

o Xcacls.exe 语法

o使用Xcacls.exe 查看权限

o Xcacls.exe 示例

?示例1

?示例2

?示例3

o NTFS 权限原则

?参考

展开全部| 关闭全部

本分步指南介绍如何使用扩展的更改访问控制列表工具(Xcacls.exe) 修改和查看文件或文件夹的NTFS 权限。

使用Xcacls.exe 可以通过命令行设置所有可在Windows 资源管理器中访问到的文件系统安全选项。Xcacls.exe 通过显示和修改文件的访问控制列表(ACL) 完成此操作。

Xcacls.exe 在Windows 2000 Professional 或Windows 2000 Server 的无值守安装中特别有用。通过使用此工具,可以为操作系统所在的文件夹设置初始访问权限。在您将软件分发到服务器或工作站时,Xcacls.exe 还提供单步保护,以防止用户删除文件夹或文件。

Xcacls.exe 实用工具包含在Windows 2000 资源工具包中。可以从Microsoft 下载中心下载以下文件:

立即下载XCacls_Installer.exe 软件包。

回到顶端

Xcacls.exe 语法

xcacls 文件名[/T] [/E] [/C] [/G user:perm;spec] [/R 用户] [/P user:perm;spec [...]] [/D 用户[...]] [/Y]

其中文件名表示ACL 或访问控制项(ACE) 通常应用于的文件或文件夹的名称。所有标准通配符均可使用。

/T递归检查当前文件夹及其所有子文件夹,对匹配的文件或文件夹应用所选的访问权限。

/E编辑ACL 而不替换它。例如,如果您运行XCACLS test.dat /G Administrator:F命令,则只有管理员拥有对Test.dat 文件的访问权限。之前应用的所有ACE 都会丢失。

/C使Xcacls.exe 在出现“拒绝访问”错误消息时继续执行。如果未指定/C,则Xcacls.exe 在出现此错误时停止执行。

/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 选项相同。请参阅本文的“Xcacls.exe 示例”部分。

/D 用户拒绝用户访问文件或目录。

/Y禁止在替换用户访问权限时出现确认提示。默认情况下,CACLS 要求确认。由于存在此功能,在批处理例程中使用CACLS 时,例程将停止响应并等待输入正确答案。引入/Y选项后可消除此确认,从而可以在批处理模式下使用Xcacls.exe。

回到顶端

使用Xcacls.exe 查看权限

Xcacls.exe 还可用于查看文件或文件夹的权限。例如,在命令提示符处键入xcacls C:\winnt,然后按Enter。下面是典型结果:

c:\WINNT BUILTIN\Users:R

BUILTIN\Users:(OI)(CI)(IO)(special access:)

GENERIC_READ

GENERIC_EXECUTE

BUILTIN\Power Users:C

BUILTIN\Power Users:(OI)(CI)(IO)C

BUILTIN\Administrators:F

BUILTIN\Administrators:(OI)(CI)(IO)F

NT AUTHORITY\SYSTEM:F

NT AUTHORITY\SYSTEM:(OI)(CI)(IO)F

BUILTIN\Administrators:F

CREATOR OWNER:(OI)(CI)(IO)F

这些ACL 标志具有下列含义:

?IO:仅继承—此标志表示此ACE 不应用于当前对象。

?CI:容器继承—此标志表示从属容器将继承此ACE。

?OI:对象继承—此标志表示从属文件将继承该ACE。

?NP:不传播—此标志表示从属对象不继续传播继承的ACE。

每行末尾的字母表示权限。例如:

?F:完全控制

?C:更改

?W:写入

回到顶端

Xcacls.exe 示例

示例 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 文件夹权限。

?管理员以及文件或文件夹的所有者控制可为该对象设置的权限。

?在更改文件夹权限时,应了解服务器上安装的程序。程序会创建自己的文件夹并打开“允许从父系来的继承权限传播到这个对象”设置。如果更改了父文件夹中的权限,则这些更改可

能会导致程序中出现问题。

警告:请记住,许多文件和文件夹通过继承接收权限。因此,在您认为只是更改了一个文件夹时,您可能更改了其他更多内容。

如何使用Xcacls.vbs 修改NTFS 权限

Microsoft 以Microsoft Visual Basic 脚本(Xcacls.vbs) 的形式提供了Extended Change Access Control List(扩展更改访问控制列表)工具(Xcacls.exe) 的更新版本。本文分步介绍如何使用Xcacls.vbs 脚本修改和查看文件或文件夹的NTFS 文件系统权限。可以从命令行使用Xcacls.vbs 设置所有可在Microsoft Windows 资源管理器中访问的文件系统安全选项。Xcacls.vbs 可显示和修改文件的访问控制列表(ACL)。

注意:Xcacls.vbs 只与Microsoft Windows 2000、Microsoft Windows XP 和Microsoft Windows Server 2003 兼容。Microsoft 不支持Xcacls.vbs。

回到顶端

设置和使用Xcacls.vbs

要设置和使用Xcacls.vbs,请按照下列步骤操作:

1.从以下Microsoft 网站获得Xcacls.vbs 的最新版本:

https://www.360docs.net/doc/0218405096.html,/download/f/7/8/f786aaf3-a37b-45ab-b0a2-8c8 c18bbf483/XCacls_Installer.exe

2.双击“Xcacls_Installer.exe”。当提示您提供放置提取文件的位置时,请指定一个位于计算

机的搜索路径设置中的文件夹(如C:\Windows)。

3.将默认脚本引擎从Wscript 更改为Cscript。(Xcacls.vbs 脚本最适合在Cscript 下运

行。)为此,请在命令提示符下键入以下内容,然后按Enter:

cscript.exe /h:cscript

注意:将默认脚本引擎更改为Cscript 只影响脚本向屏幕写入的方式。Wscript 根据“确定”

对话框分别写入每一行。Cscript 将每一行写入命令窗口。如果您不想更改默认脚本引擎,则必须使用以下命令运行脚本

cscript.exe xcacls.vbs

但是,如果将默认脚本更改为Cscript,则可以使用以下命令运行该脚本:

xcacls.vbs

.

4.要查看Xcacls.vbs 的命令语法,请在命令提示符处键入下面的命令:

xcacls.vbs /?

Xcacls.vbs 命令的语法

下面xcacls.vbs /?命令的输出描述了Xcacls.vbs 命令的语法:

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#S-1-5-21-2127521184-160...

(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 Domain\User

then do not specify SID# as one of the

users.)

GUI: Is for standard rights and can be: Permissions...

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: Permissions...

F Full control

M Modify

X read and eXecute

R Read

W Write

Advanced...

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 is for "Folder and Subfolders only" and has the

same choices as Perm.

/R user Revoke specified user's access rights. (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.

使用Xcacls.vbs 查看权限

Xcacls.vbs 还可用于查看文件或文件夹的权限。例如,如果您有一个名为C:\Test 的文件夹,在命令提示符处键入以下命令以查看文件夹权限,然后按Enter:

xcacls.vbs c:\test

下面的示例是一个典型结果:

C:\>XCACLS.VBS c:\test

Microsoft (R) Windows Script Host 5.6

版权所有 (C) Microsoft Corporation 1996-2001。保留所有权利。

Starting XCACLS.VBS (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 BUILTIN\Administrators Full Control This Folder, Subfolde

Allowed NT AUTHORITY\SYSTEM Full Control This Folder, Subfolde

Allowed Domain1\User1 Full Control This Folder Only

Allowed \CREATOR OWNER Special (Unknown) Subfolders and Files

Allowed BUILTIN\Users Read and Execute This Folder, Subfolde

Allowed BUILTIN\Users Create Folders / Appe This Folder and Subfo

Allowed BUILTIN\Users Create Files / Write This Folder and Subfo

No Auditing set

Owner:Domain1\User1

注意:在该示例中,xcacls.vbs c:\test命令的输出与显示在图形用户界面(GUI) 的文本一致。命令窗口的一些文字不完整。

输出还给出了脚本的版本、启动目录和使用的参数。

您还可以使用通配符来显示目录下匹配的文件。例如,如果键入以下命令,将会显示C:\Test 文件夹中所有具有“.log”扩展名的文件:

xcacls.vbs c:\test\*.log

示例

下列Xcacls.vbs 命令提供Xcacls.vbs 用法的一些示例:

xcacls.vbs c:\test\ /g domain\testuser1:f /f /t /e

该命令可编辑现有权限。它授予Domain\TestUser1 完全控制C:\Test 下所有文件的权限,遍历C:\Test 下的子文件夹,然后更改找到的所有文件。该命令不触及目录。

xcacls.vbs c:\test\ /g domain\testuser1:f /s /l "c:\xcacls.log"

该命令可替换现有权限。它授予Domain\TestUser1 完全控制C:\Test 下所有子文件夹的权限,而且记录到C:\Xcacls.log。该命令不触及文件,并且不遍历目录。

xcacls.vbs c:\test\readme.txt /o "machinea\group1"

该命令将自述文件的所有者更改为组MachineA\Group1。

xcacls.vbs c:\test\badcode.exe /r "machinea\group1" /r "domain\testuser1"

该命令撤消MachineA\Group1 和Domain\TestUser1 的C:\Test\Badcode.exe 权限。xcacls.vbs c:\test\subdir1 /i enable /q

该命令将打开文件夹C:\Test\Subdir1 上的继承。该命令将取消任何屏幕输出。

xcacls.vbs \\servera\sharez\testpage.htm /p "domain\group2":14

此命令通过使用Windows Management Instrumentation (WMI) 远程连接到\\ServerA\ShareZ。然后获取用于该共享的本地路径,在该路径下,它更改Testpage.htm 上的权限。它原封保留Domain\Group2 的现有权限,但是添加权限1(读取数据)和权限4(读取扩展属性)。该命令放弃此文件上的其他权限,原因是未使用/e开关。

xcacls.vbs d:\default.htm /g "domain\group2":f /server servera /user

servera\admin /pass password /e

该命令使用WMI 作为ServerA\Admin 远程连接到ServerA,然后将Default.htm 上的完全权限授予Domain\Group2。Domain\Group2 的现有权限丢失,但保留文件上的其他权限。

相关主题
相关文档
最新文档