I have a batch file with this snippet in it:
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
)
I'm not sure why, but the top line does not work. The output is this:
Z:\>systeminfo | findstr /B "Host Name:" | findstr /C:"IGSWIDWB-SET"
The syntax of the command is incorrect.
Z:\>
There is an extra space it seems after the " mark. I used to use a space between the pipes and the commands, but I removed them in an attempt to fix this error. It made no difference. I have made sure the file is in Windows format with Windows-style characters, and I don't know what to do now. This is standard batch scripting that I am using.
This code lets me figure out if it's a laptop or a desktop in an automated setup script I have developed. The hostname has a specific protocol and it will navigate through a set of installations based on this step.
Anyone know what's wrong? Thanks!
In response to [name here] here is the code that executes before it (and some after it); I have modified the words however so it is not obvious what it is. I work at an organization that prefers I don't share internal documents, but don't mind if I obfuscate it. The part that fails is on the line where the first systeminfo is.
::@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
)