我是学校 Cyber Patriot 团队的一员,我正在尝试为 Windows 图像制作一些批处理脚本。我无法让我的代码按照我试图让它工作的方式工作,我想做的是让它运行,提示用户输入,再次要求输入,然后创建一个用户帐户或删除一个。这是我的代码:
@ECHO off
xterm -e start
:start
echo 0a
echo Welcome to the Master Script For Windows CyberPatriot Completion
echo ----------------------------------------------------------------
echo What would you like to do first.
echo 1...User Add /w password pre-set (meets compexity requirements)
echo 2...User Delete (all files)
pause
set /P choice1= "Please make your choice: "
if %choice1% == 1 (
GOTO useradd
)
if %choice1% == 2 (
GOTO userdelete
)
:useradd
set /P choice2= "Please enter the name of the user you want to create (the password is pre-set
to Password123456789!): "
net user %choice2% Password123456789! /add
:userdelete
set /P choice2= "Please enter the name of the user you want to delete (WARNING! ALL FILES WILL
BE DELETED PLEASE CHECK FIRST): "
net user %choice2% /del
此外,如果您有任何批量资源、语言建议或关于我应该/不应该做什么的建议,请告诉我。预先感谢您的帮助:)
可以使用以下批处理脚本:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
color 0A
:Begin
cls
echo Welcome to the master script for Windows CyberPatriot completion
echo ----------------------------------------------------------------
echo(
echo What would you like to do first?
echo(
echo 1 ... User Add with password preset (meets complexity requirements)
echo 2 ... User Delete (all files)
echo(
%SystemRoot%\System32\choice.exe /C 12 /N /M "Please make your choice:"
if errorlevel 2 goto UserDelete
if errorlevel 1 goto UserAdd
goto Begin
:UserAdd
echo(
echo Please enter the name of the user you want to create.
echo The password is pre-set to: Password123456789!
echo(
:PromptAdd
set "NameUser="
set /P "NameUser=User name: "
if not defined NameUser goto PromptAdd
set "NameUser=%NameUser:"=%"
if not defined NameUser goto PromptAdd
echo(
%SystemRoot%\System32\net.exe user "%NameUser%" Password123456789! /ADD
echo(
if errorlevel 1 goto PromptAdd
goto EndBatch
:UserDelete
echo(
echo Please enter the name of the user you want to delete.
echo WARNING! ALL FILES WILL BE DELETED PLEASE CHECK FIRST.
echo(
:PromptDelete
set "NameUser="
set /P "NameUser=User name: "
if not defined NameUser goto PromptDelete
set "NameUser=%NameUser:"=%"
if not defined NameUser goto PromptDelete
echo(
%SystemRoot%\System32\net.exe user "%NameUser%" /DELETE
echo(
if errorlevel 1 goto PromptDelete
:EndBatch
pause
color
endlocal
要了解所使用的命令及其工作原理,请打开命令提示符窗口,执行以下命令,并完整、仔细地阅读每个命令显示的帮助页面。
choice /?
cls /?
color /?
echo /?
endlocal /?
goto /?
if /?
net /?
net user /?
pause /?
set /?
setlocal /?
另请参阅: