Batch file 为了使.bat文件再次工作,我需要删除或添加哪些代码行?

Batch file 为了使.bat文件再次工作,我需要删除或添加哪些代码行?,batch-file,Batch File,我的脚本无法运行。它会在一瞬间打开一个窗口,然后关闭它。用户名部分是把事情搞砸的地方 脚本: @echo off title File Rotation Service Login. echo Hello, please log in with your user ID. echo Username: set /Z user if %user%==(Bussjaeger) goto password cls echo Username not found in database! :pass

我的脚本无法运行。它会在一瞬间打开一个窗口,然后关闭它。用户名部分是把事情搞砸的地方

脚本:

@echo off 
title File Rotation Service Login.
echo Hello, please log in with your user ID.
echo Username: 
set /Z user
if %user%==(Bussjaeger) goto password
cls
echo Username not found in database!
:password
set/p "pass=Password"
if %pass%==(12345) goto correct
cls
echo Incorrect Password!
ping localhost -n 3 >nul
attrib +s +h (This file's name)
:correct
echo Welcome Mr.Bussjaeger. Activating file rotation..
TIMEOUT /T 3
:Start
Set "SrcDir=E:\Schem"
Set "ExtLst=*.jpg *.png *.gif"
Set "i=0"
For /F "Delims=" %%A In ('Where /R "%SrcDir%" %ExtLst%') Do (Set /A i+=1
    Call Set "$[%%i%%]=%%A")
Set /A #=(%Random%%%i)+1
Call Start "" "%%$[%#%]%%"
TIMEOUT /T 10000
goto Taskkill
:Taskkill
taskkill /IM Microsoft.Photos.exe /F
goto Start

不确定你的脚本应该做什么,但是,为了让它运行,我做了一些更正。它将:

  • 请求一个用户ID,并且只有在“Bussjaeger”键入大写字母“B”时才会继续
  • 询问设置为“12345”的密码
  • 我不知道其他线路应该做什么,但它无论如何都会运行
  • 以下是评论:

    @echo off 
    title File Rotation Service Login.
    rem Variables are set to blank to avoid them to have old strings set in the memory.
    set user=
    set pass=
    
    :start
    cls
    echo Hello, please log in with your user ID.
    set /p user=User (Case sensitive): 
    rem The IF command will be case sensitive if the /i option is not used.
    rem In order to avoid case sensitive, the command should be:
    rem if /i "%user%" == "Bussjaeger" (
    if "%user%" == "Bussjaeger" (
    goto password
    ) else (
    cls
    echo Username not found in database!
    echo Press any key to try again . . .
    pause > nul
    goto start
    )
    
    :password
    set /p pass=Password: 
    if "%pass%" == "12345" (
    goto correct
    ) else (
    cls
    echo Incorrect Password!
    goto password
    )
    
    rem What is the use of the next two lines?
    ping localhost -n 3 >nul
    attrib +s +h (This file's name)
    
    :correct
    echo Welcome Mr.Bussjaeger. Activating file rotation..
    timeout /t 3
    
    :start_work
    set "srcdir=e:\schem"
    set "extlst=*.jpg *.png *.gif"
    set "i=0"
    
    rem The following line will fail. Sixtax is not correct.
    for /f "delims=" %%a in ('where /r "%srcdir%" %extlst%') do (
        set /a "i+=1"
        call set "$[%%i%%]=%%a"
    )
    set /a #=(%random%%%i)+1
    
    rem Not sure what the following lines should do.
    call start "" "%%$[%#%]%%"
    timeout /t 10000
    goto taskkill
    
    :taskkill
    taskkill /im microsoft.photos.exe /f
    goto start
    

    实际上是用户名和密码的一部分吗?不,它们不是,但是我一直被教导它们必须在那里才能工作。相反,这就是破坏它的原因。好吧,还有一个事实,
    集合
    中没有
    /Z
    标志。你能指出代码需要修改的地方吗。正如在/Z flagOk中一样,我删除了(和),但是文件仍然有问题