中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-02 20:29
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » How to use a batch file to modify file or folder attributes???
Printable Version  3,551 / 19
Floor1 想学DOS Posted 2003-03-10 00:00
中级用户 Posts 50 Credits 234
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!!!
Floor2 Lydong Posted 2003-03-10 00:00
元老会员 Posts 407 Credits 1,468 From 广州
Try this command:
ATTRIB -R -S -H C:\DIR
Floor3 Wengier Posted 2003-03-10 00:00
系统支持 Posts 10,521 Credits 27,736
That’s not right. This involves file permissions, not file attributes. You should use the CACLS command, not the ATTRIB command.
Floor4 想学DOS Posted 2003-03-11 00:00
中级用户 Posts 50 Credits 234
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!!!
Floor5 Roy Posted 2003-03-11 00:00
管理员 Posts 1,633 Credits 4,869
Floor6 Wengier Posted 2003-03-11 00:00
系统支持 Posts 10,521 Credits 27,736
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"
Floor7 想学DOS Posted 2003-03-11 00:00
中级用户 Posts 50 Credits 234
Doesn’t work,
it says:
C:\>attrib -r c:\Program Files
Parameter format not correct -
Floor8 Wengier Posted 2003-03-11 00:00
系统支持 Posts 10,521 Credits 27,736
Use quotation marks: ATTRIB -R "C:\Program Files"
Floor9 想学DOS Posted 2003-03-11 00:00
中级用户 Posts 50 Credits 234
wengier,
It works now, thank you,
I’ve learned something new again.
And thanks to all the friends here for your help!
Floor10 想学DOS Posted 2003-03-11 00:00
中级用户 Posts 50 Credits 234
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.
Floor11 flysp Posted 2006-04-29 04:07
中级用户 Posts 41 Credits 207
ATTRIB -R "C:\Program Files"
^_^
Learned something new

[ Last edited by flysp on 2006-4-29 at 04:17 ]
Floor12 xuantian Posted 2006-04-29 12:03
高级用户 Posts 282 Credits 587
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
Floor13 3742668 Posted 2006-04-29 12:58
荣誉版主 Posts 718 Credits 2,013
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.
Floor14 xuantian Posted 2006-04-29 14:42
高级用户 Posts 282 Credits 587
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)
Floor15 3742668 Posted 2006-05-04 14:24
荣誉版主 Posts 718 Credits 2,013
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.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023