<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>胡杨 &#187; 批处理</title>
	<atom:link href="http://www.hu-yang.com/tag/%e6%89%b9%e5%a4%84%e7%90%86/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hu-yang.com</link>
	<description>背水一战</description>
	<lastBuildDate>Tue, 01 Mar 2011 06:29:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>批处理批量建立用户并分配权限</title>
		<link>http://www.hu-yang.com/%e6%89%b9%e5%a4%84%e7%90%86%e6%89%b9%e9%87%8f%e5%bb%ba%e7%ab%8b%e7%94%a8%e6%88%b7%e5%b9%b6%e5%88%86%e9%85%8d%e6%9d%83%e9%99%90/</link>
		<comments>http://www.hu-yang.com/%e6%89%b9%e5%a4%84%e7%90%86%e6%89%b9%e9%87%8f%e5%bb%ba%e7%ab%8b%e7%94%a8%e6%88%b7%e5%b9%b6%e5%88%86%e9%85%8d%e6%9d%83%e9%99%90/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 06:27:05 +0000</pubDate>
		<dc:creator>胡杨</dc:creator>
				<category><![CDATA[电脑]]></category>
		<category><![CDATA[net user]]></category>
		<category><![CDATA[批处理]]></category>
		<category><![CDATA[批量建立用户]]></category>

		<guid isPermaLink="false">http://www.hu-yang.com/?p=41</guid>
		<description><![CDATA[　　这是我多年前写的一个批处理文件，主要实现：批量建立一个班级的学生用户，并分配权限，通过网上邻居一个学生用户只能访问一个相对应的目录。
　　例：要建立计算机0210班级用户,人数为50,根目录为d盘的用户群的话，执行“creauser 计算机0210 jsj0210 50 d:”后，则将建立“jsj0210”这个组，“jsj021001 &#8212; jsj021050”这50个用户（密码和用户名称相同），并将在D盘建立如下目录：
　　d:
　　&#124;__ jsj0210　　（jsj0210这个组都能访问，但不能写操作）
　　　　　&#124;__ 01　　（只有jsj021001这个用户能访问，并能写操作）
　　　　　&#124;__ 02
　　　　　&#124;__ &#8230;
　　creauser.bat文件代码如下：

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@echo off
rem 建立用户并分配权限
rem 格式: creauser 班级名称 班级代称 人数 建立目录的根目录
rem 例: 要建立计算机0210班级用户,人数为50,根目录为d盘的话.
rem 则命令是:creauser 计算机0210 jsj0210 50 d:
&#160;
if &#34;%1&#34;==&#34;&#34; goto error
if &#34;%1&#34;==&#34;/?&#34; goto error
if &#34;%4&#34;==&#34;&#34; goto error
&#160;
echo ====建立班级组
net group %2 /add /comment:&#34;%1&#34;
&#160;
echo ====建立班级组上的用户,并把各用户加到班级组中去
for /L %%i in &#40;1,1,9&#41; do net user %20%%i %20%%i /comment:&#34;%1&#34; /add &#38; net group [...]]]></description>
			<content:encoded><![CDATA[<p>　　这是我多年前写的一个批处理文件，主要实现：批量建立一个班级的学生用户，并分配权限，通过网上邻居一个学生用户只能访问一个相对应的目录。</p>
<p>　　例：要建立计算机0210班级用户,人数为50,根目录为d盘的用户群的话，执行“creauser 计算机0210 jsj0210 50 d:”后，则将建立“jsj0210”这个组，“jsj021001 &#8212; jsj021050”这50个用户（密码和用户名称相同），并将在D盘建立如下目录：<br />
　　d:<br />
　　|__ jsj0210　　（jsj0210这个组都能访问，但不能写操作）<br />
　　　　　|__ 01　　（只有jsj021001这个用户能访问，并能写操作）<br />
　　　　　|__ 02<br />
　　　　　|__ &#8230;</p>
<p><span id="more-41"></span>　　creauser.bat文件代码如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;"><span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">echo</span> off
<span style="color: #808080; font-style: italic;">rem 建立用户并分配权限</span>
<span style="color: #808080; font-style: italic;">rem 格式: creauser 班级名称 班级代称 人数 建立目录的根目录</span>
<span style="color: #808080; font-style: italic;">rem 例: 要建立计算机0210班级用户,人数为50,根目录为d盘的话.</span>
<span style="color: #808080; font-style: italic;">rem 则命令是:creauser 计算机0210 jsj0210 50 d:</span>
&nbsp;
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>&quot;==&quot;&quot; <span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">error</span>
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>&quot;==&quot;/?&quot; <span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">error</span>
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>&quot;==&quot;&quot; <span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">error</span>
&nbsp;
<span style="color: #b1b100; font-weight: bold;">echo</span> ====建立班级组
net group <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span> /add /comment:&quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>&quot;
&nbsp;
<span style="color: #b1b100; font-weight: bold;">echo</span> ====建立班级组上的用户,并把各用户加到班级组中去
<span style="color: #00b100; font-weight: bold;">for</span> /L <span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span> <span style="color: #00b100; font-weight: bold;">do</span> net user <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #cc66cc;">0</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #cc66cc;">0</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> /comment:&quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>&quot; /add &amp; net group <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #cc66cc;">0</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> /add
<span style="color: #00b100; font-weight: bold;">for</span> /L <span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #33cc33;">%</span><span style="color: #448888;">3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #00b100; font-weight: bold;">do</span> net user <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> /comment:&quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>&quot; /add &amp; net group <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> /add
&nbsp;
<span style="color: #b1b100; font-weight: bold;">echo</span> ====建立班级目录并分配权限
<span style="color: #b1b100; font-weight: bold;">md</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>\<span style="color: #33cc33;">%</span><span style="color: #448888;">2</span> &amp; <span style="color: #b1b100; font-weight: bold;">echo</span> y|cacls <span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>\<span style="color: #33cc33;">%</span><span style="color: #448888;">2</span> /t /c /p administrators:f <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span>:r
<span style="color: #808080; font-style: italic;">rem 建立学生目录01,02,03, ..., 并分配权限</span>
<span style="color: #00b100; font-weight: bold;">for</span> /L <span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span> <span style="color: #00b100; font-weight: bold;">do</span> <span style="color: #b1b100; font-weight: bold;">md</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>\<span style="color: #33cc33;">%</span><span style="color: #448888;">2</span>\<span style="color: #cc66cc;">0</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> &amp; <span style="color: #b1b100; font-weight: bold;">echo</span> y|cacls <span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>\<span style="color: #33cc33;">%</span><span style="color: #448888;">2</span>\<span style="color: #cc66cc;">0</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> /t /c /p <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #cc66cc;">0</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span>:c administrators:f
<span style="color: #808080; font-style: italic;">rem 建立学生目录10,12,13, ...</span>
<span style="color: #00b100; font-weight: bold;">for</span> /L <span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #33cc33;">%</span><span style="color: #448888;">3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #00b100; font-weight: bold;">do</span> <span style="color: #b1b100; font-weight: bold;">md</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>\<span style="color: #33cc33;">%</span><span style="color: #448888;">2</span>\<span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> &amp; <span style="color: #b1b100; font-weight: bold;">echo</span> y|cacls <span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>\<span style="color: #33cc33;">%</span><span style="color: #448888;">2</span>\<span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> /t /c /p <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span>:c administrators:f
&nbsp;
<span style="color: #b1b100; font-weight: bold;">echo</span> ====共享目录
net share <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span>=<span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>\<span style="color: #33cc33;">%</span><span style="color: #448888;">2</span>
&nbsp;
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">end</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">error</span>
<span style="color: #b1b100; font-weight: bold;">echo</span> 格式: creuser 班级名称 班级代称 人数 建立目录的根目录
<span style="color: #b1b100; font-weight: bold;">echo</span> 如: 要建立计算机0210班级用户,人数为<span style="color: #cc66cc;">50</span>,想把班级目录建在D盘的话
<span style="color: #b1b100; font-weight: bold;">echo</span> 则: creauser 计算机0210 jsj0210 <span style="color: #cc66cc;">50</span> d:
&nbsp;
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">end</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">end</span>
<span style="color: #b1b100; font-weight: bold;">echo</span> ====成功完成. END</pre></td></tr></table></div>

<p>　　deleuser.bat比较简单就不介绍了，内容如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;"><span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">echo</span> off
<span style="color: #808080; font-style: italic;">rem 删除班级用户及目录</span>
<span style="color: #808080; font-style: italic;">rem 格式: deleuser 班级名称 班级代称 人数 建立目录的根目录</span>
<span style="color: #808080; font-style: italic;">rem 例: 要删除计算机0210班级用户,人数为50,根目录为d盘的话.</span>
<span style="color: #808080; font-style: italic;">rem 则命令是:deleuser 计算机0210 jsj0210 50 d:</span>
&nbsp;
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>&quot;==&quot;&quot; <span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">error</span>
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>&quot;==&quot;/?&quot; <span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">error</span>
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>&quot;==&quot;&quot; <span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">error</span>
&nbsp;
<span style="color: #b1b100; font-weight: bold;">echo</span> ====删除班级组上的用户
<span style="color: #00b100; font-weight: bold;">for</span> /L <span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span> <span style="color: #00b100; font-weight: bold;">do</span> net user <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #cc66cc;">0</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> /delete
<span style="color: #00b100; font-weight: bold;">for</span> /L <span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #33cc33;">%</span><span style="color: #448888;">3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #00b100; font-weight: bold;">do</span> net user <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span><span style="color: #33cc33;">%%</span><span style="color: #448888;">i</span> /delete
&nbsp;
<span style="color: #b1b100; font-weight: bold;">echo</span> ====删除班级组
net group <span style="color: #33cc33;">%</span><span style="color: #448888;">2</span> /delete
&nbsp;
<span style="color: #b1b100; font-weight: bold;">echo</span> ====删除班级目录
<span style="color: #b1b100; font-weight: bold;">rd</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">4</span>\<span style="color: #33cc33;">%</span><span style="color: #448888;">2</span> /s /q
<span style="color: #808080; font-style: italic;">rem 下面命令只删除文件不删除目录</span>
<span style="color: #808080; font-style: italic;">rem del %4\%2 /s a /q /f</span>
&nbsp;
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">end</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">error</span>
<span style="color: #b1b100; font-weight: bold;">echo</span> 格式: deleuser 班级名称 班级代称 人数 建立目录的根目录
<span style="color: #b1b100; font-weight: bold;">echo</span> 如: 要删除计算机0210班级用户,人数为<span style="color: #cc66cc;">50</span>,想把班级目录建在D盘的话
<span style="color: #b1b100; font-weight: bold;">echo</span> 则: deleuser 计算机0210 jsj0210 <span style="color: #cc66cc;">50</span> d:
&nbsp;
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">end</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">end</span>
<span style="color: #b1b100; font-weight: bold;">echo</span> ====成功完成. END</pre></td></tr></table></div>

<p>　　最后有2点说明：<br />
　　（1）由于net user命令并不能指定用户的密码到期时间，而如果你需要用户密码比较长的存留期的话，简单的方法就是到［域安全策略］里把［密码最长存留期］设的长一点。（net user 用户名，可以查看密码到期时间。）<br />
　　（2）如果你要对每个目录的空间大小限额的话，请把目录建在NTFS文件格式的逻辑分区上，再启用这个逻辑分区的磁盘配额，设置每个用户磁盘空间限额，这样就相当于对每个目录的空间进行限额了。</p>
<p>　　文件打包下载，<a href="http://www.hu-yang.com/uploads/2009/06/Manauser.zip">ManaUser.zip</a>(2KB)。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hu-yang.com/%e6%89%b9%e5%a4%84%e7%90%86%e6%89%b9%e9%87%8f%e5%bb%ba%e7%ab%8b%e7%94%a8%e6%88%b7%e5%b9%b6%e5%88%86%e9%85%8d%e6%9d%83%e9%99%90/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

