if用于将用户添加到批处理文件中的组的语句

时间:2016-06-02 10:19:05

标签: windows batch-file cmd

我目前正在制作一些代码,将本地用户添加到群组中,而且我很困难。执行这六行时会出现问题:

if /I "%choix%"=="1" do net localgroup %grp1% %%A /add
if /I "%choix%"=="2" do net localgroup %grp2% %%A /add
if /I "%choix%"=="3" do (
    net localgroup %grp1% %%A /add
    net localgroup %grp2% %%A /add
)

这是我的完整代码:

@ echo off

:debut
set /P fichiercsv="Complete file path :"
set /P grp1="Enter the first group name :"
set /P grp2="Enter the second group name :"
net localgroup %grp1% /add
net localgroup %grp2% /add
for /F "eol=; tokens=1,2 delims=," %%A in (%fichiercsv%) do net user %%A %%B /add
pause
for /F "eol=; tokens=1,2 delims=," %%A in (%fichiercsv%) do (
    cls
    echo In which group do you want to add %%A?
    echo 1. %grp1%
    echo 2. %grp2%
    echo 3. %grp1% et %grp2%
    set /P choix="Enter a number : "
    if /I "%choix%"=="1" do net localgroup %grp1% %%A /add
    if /I "%choix%"=="2" do net localgroup %grp2% %%A /add
    if /I "%choix%"=="3" do (
        net localgroup %grp1% %%A /add
        net localgroup %grp2% %%A /add
    )
)

echo All users where added to the groups
echo Do you want to specify another file ?
set /P continuer="continue whit another csv file [o/n] ?"
if /I "%continuer%" EQU "o" goto debut
if /I "%continuer%" EQU "n" goto fin

:fin
echo Resultat final:
type %fichiercsv%
echo Au revoir !

0 个答案:

没有答案