试图批量制作“操作系统”

时间:2019-10-14 08:33:12

标签: batch-file crash

    @echo off
:load
rem imitation of loading the os
color 70
ver
title boot
echo please wait...
ping localhost -n 3 >nul
cls
systeminfo
rem in here user types name he wants to be his account name
:login
title login
cls
date
cls
echo welcome to windows 71
echo before we bigen please type your name
set /P_name=here:
if %name%=admin goto admin
if not goto ms
rem ms=menu start
:ms 
echo %time%
echo hello %name% 
echo type HELP for list to commands
set /P_command=here:
if %command%=help goto help
if %command%=exit goto exit
if %command%=calendar goto cal
if not goto wc
rem wc=wrong command
:admin
echo hello %name% to the admin panel
echo type HELP for list to commands
set /P_command=here:
if %command%=help goto help
if %command%=exit goto exit
if %command%=calendar goto cal

所以问题是,它在:LOGIN部分之后崩溃了,我不知道该怎么办! 所以我试图批量制作一个操作系统(类似于MS-DOS),但是在“登录”部分之后它崩溃了 我尝试了我能想到的所有方法,但它也没有起作用,我还想制作一个保存文件,以便用户可以为其“帐户”设置密码。

2 个答案:

答案 0 :(得分:0)

如以上注释中所述,您需要正确使用变量,但是您可以为命令使用rsi而不是choice

set /p

一些注意事项。您不需要转到@echo off :load rem imitation of loading the os color 70 ver title boot echo please wait... timeout /t 3 >nul cls systeminfo rem in here user types name he wants to be his account name :login title login cls date /t timeout /t 2>nul cls echo welcome to windows 71 echo Before we begin please type your name set /P "_name=here:" if /i "_%name%"=="admin" goto admin rem ms=menu start :ms echo %time% echo hello %_name% echo type HELP for list to commands CHOICE /C HEC /M "Press H for Help, E to exit C for Calender." goto opt%errorlevel% :admin echo hello %_name% to the admin panel echo type HELP for list to commands CHOICE /C HEC /M "Press H for Help, E to exit C for Calender." goto opt%errorlevel% :opt1 echo Help stuff goes here goto :eof :opt2 exit :opt3 echo Calenders stuff goes here ,因为该用户不是管理员,因为不会满足非管理员的要求,我们将自动进入ms标签。

注意代码中的问题所在。即ms应该是if %name%=admin,并带有双等号和名称中的下划线。它也用双引号引起来,以确保我们进行匹配时不会出现多余的空格。最后,if "%_name%"=="admin"选项可以在任何情况下捕获ADMIN。

有关这些功能的更多帮助,请参见命令行中的/Iif /?

答案 1 :(得分:0)

好的,此代码是完全错误的。 我修好了。

@echo off
:load
rem imitation of loading the os
color 70
title boot
echo please wait...
ping localhost -n 3 >nul
cls
rem in here user types name he wants to be his account name
:login
title login
cls
echo Welcome to Microsoft Windows 7!
echo Before we begin, please type your name.
set /p name=here:
if "%name%"=="admin" goto admin
if not "%name%"=="admin" goto ms
rem ms=menu start
:ms 
echo %time%
echo Hello %name% 
echo Type HELP for list to commands
set /p command=here:
if "%command%"=="help" goto help
if "%command%"=="exit" goto exit
if "%command%"=="calendar" goto cal
goto ms
rem wc=wrong command
:admin
CLS
echo hello %name% to the admin panel
echo type HELP for list to commands
set /P command=here:
if "%command%"=="help" goto help
if "%command%"=="exit" goto exit
if "%command%"=="calendar" goto cal

GOTO :ADMIN

好的,但是您不需要启动systeminfo之类的东西。