China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-02 21:40
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to use a batch file to modify file or folder attributes??? View 3,555 Replies 19
Original Poster Posted 2003-03-10 00:00 ·  中国 广东 东莞 电信
中级用户
★★
Credits 234
Posts 50
Joined 2002-11-20 00:00
23-year member
UID 294
Gender Male
Status Offline
Under WIN2000,
suppose I want to change the attributes of the DIR directory on drive C:\ to “deny EVERYONE read access”,
how should I write a BAT file for that?
Thanks!!!
Floor 2 Posted 2003-03-10 00:00 ·  中国 广东 广州 增城区 电信
元老会员
★★★
Credits 1,468
Posts 407
Joined 2002-10-21 00:00
23-year member
UID 34
Gender Male
From 广州
Status Offline
Try this command:
ATTRIB -R -S -H C:\DIR
欢迎大家观临我的个人主页:

http://dosdiy.bluepc.com.cn/
http://dosdiy.ys168.com/


EMAIL: lydong@china.com.cn lydong@yeah.net
----------------------------------------------
Floor 3 Posted 2003-03-10 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
That’s not right. This involves file permissions, not file attributes. You should use the CACLS command, not the ATTRIB command.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 4 Posted 2003-03-11 00:00 ·  中国 广东 东莞 电信
中级用户
★★
Credits 234
Posts 50
Joined 2002-11-20 00:00
23-year member
UID 294
Gender Male
Status Offline
I want to restrict the use of games in WIN2000, and used the following statements:
cacls c:\winnt\system32\freecell.exe /d everyone
cacls c:\winnt\system32\winmine.exe /d everyone
cacls c:\winnt\system32\sol.exe /d everyone
cacls c:\Program Files\Windows NT\games\cblocks.exe /d everyone
cacls C:\Program Files\Windows NT\Pinball\pinball.exe /d everyone
As a result, the first three statements worked, but the last two did not.
I guess it is because the Program files folder on the system drive is by default "read-only",
so I used attrib -r c:\program files\33.txt /d,
but it still didn’t work,
how can I remove the read-only attribute of Program files before executing the CACLS command???
Thanks!!!
Floor 5 Posted 2003-03-11 00:00 ·  中国 香港 香港教育大学
管理员
★★★★
專業島民
Credits 4,869
Posts 1,633
Joined 2002-12-10 00:00
23-year member
UID 465
Gender Male
Status Offline
我的網站:http://mw16.2ya.com/ 我的網誌: http://scrappedblog.blogspot.com/
~
我的Winamp正在播放的歌曲:
Floor 6 Posted 2003-03-11 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
That’s not the reason, but because C:\Program Files is a long filename with spaces, it should be enclosed in quotation marks, otherwise it won’t work, for example: ATTRIB -R "C:\Program Files"
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 7 Posted 2003-03-11 00:00 ·  中国 广东 东莞 电信
中级用户
★★
Credits 234
Posts 50
Joined 2002-11-20 00:00
23-year member
UID 294
Gender Male
Status Offline
Doesn’t work,
it says:
C:\>attrib -r c:\Program Files
Parameter format not correct -
Floor 8 Posted 2003-03-11 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Use quotation marks: ATTRIB -R "C:\Program Files"
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 9 Posted 2003-03-11 00:00 ·  中国 广东 东莞 电信
中级用户
★★
Credits 234
Posts 50
Joined 2002-11-20 00:00
23-year member
UID 294
Gender Male
Status Offline
wengier,
It works now, thank you,
I’ve learned something new again.
And thanks to all the friends here for your help!
Floor 10 Posted 2003-03-11 00:00 ·  中国 广东 东莞 电信
中级用户
★★
Credits 234
Posts 50
Joined 2002-11-20 00:00
23-year member
UID 294
Gender Male
Status Offline
OK. The steps to disable games under WIN200 are:
cacls c:\winnt\system32\freecell.exe /d everyone
cacls c:\winnt\system32\winmine.exe /d everyone
cacls c:\winnt\system32\sol.exe /d everyone
ATTRIB -R "C:\Program Files"
cacls "c:\Program Files\Windows NT\games\cblocks.exe" /d everyone
cacls "C:\Program Files\Windows NT\Pinball\pinball.exe" /d everyone
Of course, this batch file has to be run under an administrator account,
and even then it can only restrict ordinary users.
I wonder whether this method is reliable?
Comments are welcome.
Floor 11 Posted 2006-04-29 04:07 ·  中国 河南 郑州 电信
中级用户
Credits 207
Posts 41
Joined 2004-10-24 00:00
21-year member
UID 32885
Gender Male
Status Offline
ATTRIB -R "C:\Program Files"
^_^
Learned something new

[ Last edited by flysp on 2006-4-29 at 04:17 ]
Floor 12 Posted 2006-04-29 12:03 ·  中国 四川 绵阳 电信
高级用户
★★
Credits 587
Posts 282
Joined 2006-04-10 03:40
20-year member
UID 53599
Gender Male
Status Offline
Somewhat unnecessary, under windows you can do it with a couple of mouse clicks, no need to make it this troublesome. (Of course, the prerequisite is that it must be an NT partition and you must have administrative privileges)
If it’s under DOS, there’s no way to restrict it at all
Floor 13 Posted 2006-04-29 12:58 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
As long as a script is useful, it can’t be considered a redundant script. After all, I once tried manually setting permissions one by one right after installing the system; once the workload gets big, a script shows its usefulness.
Granted, xuantian is considering the limitations of this script, so he thinks it is somewhat unnecessary. However, this board is now DOS Batch Files & Script Technology (Batch Processing Room), so there’s no need to focus too much on the connection with DOS. On the contrary, I hope this board can embrace everything; as long as it is related to scripts, everyone can bring it out to study and discuss together.
Re 想学DOS
“As a result, the first three statements worked, but the last two did not.
I guess it is because the Program files folder on the system drive is by default "read-only"..."
It probably isn’t because the program files folder has the read-only attribute, but because from the start the paths in your commands contained spaces. After all, the file access control list (ACL) and file attributes are two different things.
Floor 14 Posted 2006-04-29 14:42 ·  中国 四川 绵阳 电信
高级用户
★★
Credits 587
Posts 282
Joined 2006-04-10 03:40
20-year member
UID 53599
Gender Male
Status Offline
Technically speaking... (the settings after installing an NT system are not that many and not that complicated)
Also, when writing NT scripts/batch files, you should develop a good habit of using quotation marks "", which can reduce some unnecessary trouble (this is probably also one of the advantages of supporting long filenames, or names containing spaces and some special symbols)
Floor 15 Posted 2006-05-04 14:24 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Originally posted by xuantian at 2006-4-29 14:42:
Technically speaking... (the settings after installing an NT system are not that many and not that complicated)
..

Let me argue a bit:
If you don’t have higher requirements, then of course it’s relatively simple; technically speaking, you can leave it unset.
But if you want to fully bring out the system’s functions and guarantee system security as much as possible, then carefully setting everything once is very necessary.
My computer runs XP PRO SP2. Since I bought it and brought it home, I’ve only installed the system twice. The first time was when I bought it; it took more than half an hour to finish all the settings, and I did not install any system security tools other than windows itself (firewall, antivirus software, etc...). I also usually like downloading all sorts of messy software to play with. As I recall, before the second reinstall I had only gotten one piece of spyware, and I removed it manually in the end. Later, because of disk space and because the system had been in use for almost 2 years and had become a bit slower than at the beginning, I reinstalled it a second time, and I’ve been using it ever since.
Actually, system setup can be considered a field of study in itself.
Forum Jump: