我有一个包含此代码段的批处理文件:
systeminfo|findstr /B "Host Name:"|findstr /C:"COMPNAME-SET"
if %ERRORLEVEL% EQU 0 (
echo This computer is either a test machine or has not had it's name configured yet. Continuing will run the script in test mode.
pause
)
我不知道为什么,但顶线不起作用。输出是这样的:
Z:\>systeminfo | findstr /B "Host Name:" | findstr /C:"IGSWIDWB-SET"
The syntax of the command is incorrect.
Z:\>
“标记后似乎有一个额外的空格。我曾经在管道和命令之间使用空格,但我删除了它们以尝试修复此错误。没有区别。我确保文件在带有 Windows 风格字符的 Windows 格式,我现在不知道该怎么办。这是我正在使用的标准批处理脚本。
这段代码让我在我开发的自动设置脚本中确定它是笔记本电脑还是台式机。主机名具有特定的协议,它将根据此步骤浏览一组安装。
有谁知道怎么了?谢谢!
作为对 [name here] 的回应,这里是在它之前执行的代码(以及在它之后执行的一些代码);但是我已经修改了这些词,所以不清楚它是什么。我在一个喜欢我不共享内部文档的组织工作,但不介意我是否混淆它。失败的部分在第一个 systeminfo 所在的行上。
::@echo off
setlocal
set BATDIR=%~dp0%
set SCRIPTVER=3.2
cls
set SUBDEPARTMENT=false
if not [%1]==[] (
if "%1" EQU "/help" (
echo Calling For Help.
CALL :HELP
goto :EOF
)
if "%1" EQU "/SUBDEPARTMENT" (
set SUBDEPARTMENT=true
echo Set SUBDEPARTMENT options to true.
::echo SUBDEPARTMENT Switch does not work on this version of the script. ::CD VERSION ONLY :: Continuing without.
echo.
goto CONTINUE
)
)
:Continue
color 0B
echo XXXX AutoInstaller Script for Windows 7/XP (x86/amd64)
echo Version %SCRIPTVER% - Build Date: 11/14/2012
echo Estimated Install Time: 80(Core) to 180(SUBDEPARTMENT) minutes
echo Computer will reboot to phase 2 once completed.
echo A log file for this script can be found at %USERPROFILE%\AutoInstallerLog.txt
echo ---------------------------------------------------------------
echo Preparing System...
echo Auto Install Log, generated on: > %USERPROFILE%\AutoInstallerLog.txt
echo AutoInstaller Script Version: %SCRIPTVER% >> %USERPROFILE%\AutoInstallerLog.txt
DATE /T >> %USERPROFILE%\AutoInstallerLog.txt
echo This log file reflects what steps completed in the ASI script. It does not mean they completed correctly so please make sure that all software is installed correctly!
echo Make sure the computer has been renamed to match the type [e.g. COMPUTER_PROTOCOL]. Make sure it has also been rebooted it so that it takes effect.
echo SystemInfo Output: >> %USERPROFILE%\AutoInstallerLog.txt
systeminfo >> %USERPROFILE%\AutoInstallerLog.txt
::Setting script parameters
echo.
echo Configuring script parameters.
::Check if it's a test machine
echo systeminfo^|findstr /B "Host Name:"^|findstr /C:"TESTCOMP_NAME"
systeminfo|findstr /B "Host Name:"|findstr /C:"TESTCOMP_NAME"
if %ERRORLEVEL% EQU 0 (
echo This computer is either a test machine or has not had it's name configured yet. Continuing will run the script in test mode.
pause
set TestComp=1
::TestOS
systeminfo|findstr /C:"XP Professional"
if %ERRORLEVEL% EQU 0 (
set OS=XP
goto :finishTestOS
)
systeminfo | findstr /C:"7 Enterprise"
if %ERRORLEVEL% EQU 0 (
set OS=7
goto :finishTestOS
)
:finishTestOS
set STYLE=workstation
goto :AdminCheck
)
::Debug Statement:
echo NEXT PArT!!! LINE 67
::::OS Version
:getOS
systeminfo|findstr /C:"XP Professional"
if %ERRORLEVEL% EQU 0 (
set OS=XP
goto :finishOS
)
systeminfo|findstr /C:"7 Enterprise"
if %ERRORLEVEL% EQU 0 (
set OS=7
goto :finishOS
)
:finishOS
echo This system is running Windows %OS%.
::Get Form Factor
:getStyle
systeminfo | findstr /B "Host Name:" | findstr /C:"WORKSTATION_PROTOCOL"
if %ERRORLEVEL% EQU 0 (
set STYLE=laptop
) else (
set STYLE=workstation
)
:finishStyle
echo This system is a %STYLE%.
if not defined STYLE (
echo System style not configured correctly. The name of the computer likely does not follow protocol, it must have PROTOCOLS in it.
goto :ERROREND
)
if not defined OS (
echo OS not detected properly. The script may need to be updated to detect new versions of Windows.
goto :ERROREND
)