Board logo

标题: [其他] 修改计算机名的BAT代码为何echo之后无法显示变量内容? [打印本页]

作者: wd4455    时间: 2018-12-10 16:21     标题: 修改计算机名的BAT代码为何echo之后无法显示变量内容?

  1. if "%name%"=="%computername%" (
  2.     >>%run_log% echo 计算机名符合要求,跳过修改
  3. ) else (
  4.     echo 正在修改计算机名
  5.     wmic computersystem where "name='%computername%'" call rename %name%
  6.     if errorlevel 1 (
  7.         >>%run_log% echo ********************修改计算机名为:"%name%"失败 ********************
  8.     ) else (
  9.         >>%run_log% echo 修改计算机名为:"%name%"成功
  10.     )
  11. )
复制代码
脚本运行结果没有显示%name%变量.请问这是什么原因造成的?
作者: Batcher    时间: 2018-12-10 18:01

把 >>%run_log%删掉试试
作者: wd4455    时间: 2018-12-10 18:51

if "%name%"=="%computername%" (
    >>%run_log% echo 计算机名符合要求,跳过修改
) else (
    echo 正在修改计算机名
    wmic computersystem where "name='%computername%'" call rename %name%
    if errorlevel 1 (
        >>echo ********************修改计算机名为:"%name%"失败 ******************** >>%run_log%
    ) else (
        >>echo 修改计算机名为:"%name%"成功 >>%run_log%
    )
)




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2