File 批处理文件问题-嵌套/分支';如果';陈述

File 批处理文件问题-嵌套/分支';如果';陈述,file,if-statement,batch-file,nested,branch,File,If Statement,Batch File,Nested,Branch,我正试图让它工作,但显然Windows不喜欢它。一旦它到达批处理文件的这一部分,.bat就会关闭 if %UserName% = Semedar ( if %UserName% 1394677 ( set administrator=true ) ) if %administrator% == "true" ( echo This shows up for the admin ) Else ( echo otherwise if %UserNam

我正试图让它工作,但显然Windows不喜欢它。一旦它到达批处理文件的这一部分,.bat就会关闭

if %UserName% = Semedar (
    if %UserName% 1394677 (
        set administrator=true
    )
)

if %administrator% == "true" (
    echo This shows up for the admin
) Else (
    echo otherwise if %UserName% doesn't equal "Semedar" or "1394677" this shows up.
)

您需要在if语句中使用比较运算符(前两个ifs中缺少)
eq
=
您还将管理员设置为
true
,但将其与
“true”
进行比较,两者不相同

请注意,批处理文件对空间非常敏感,因此最好将比较用引号括起来,因为Windows用户名可能包含空格。您的意思是说,如果用户名是Semedar或1394677,则将administrator设置为true?因为使用嵌套的if语句,它将检查UserName是否等于这两者

if "%UserName%" EQU "Semedar" set "administrator=true"
if "%UserName%" EQU "1394677" set "administrator=true"

if "%administrator%" EQU "true" (
    echo This shows up for the admin
) Else (
    echo otherwise if %UserName% doesn't equal "Semedar" or "1394677" this shows up.
)