このスニペットを含むバッチ ファイルがあります。
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
)