Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;Windows在这个时候出人意料;尝试比较批处理脚本中的2个字符串时出错_Windows_Batch File_If Statement_Windows 7_Windows Xp - Fatal编程技术网

&引用;Windows在这个时候出人意料;尝试比较批处理脚本中的2个字符串时出错

&引用;Windows在这个时候出人意料;尝试比较批处理脚本中的2个字符串时出错,windows,batch-file,if-statement,windows-7,windows-xp,Windows,Batch File,If Statement,Windows 7,Windows Xp,我正在编写一个批处理脚本,以使用USMT将计算机从XP更新到7。因为USMT有一个在OS升级之前需要运行的scanstate组件和一个在OS升级之后必须运行的loadstate计算机,所以我尝试使用if语句来检查操作系统是什么,然后运行正确的命令。我是新的批处理文件,但从我一直在阅读的一切,似乎我写得很好,但我显然搞砸了某个地方。我得到一个“Windows此时出现意外错误”。我还知道,由于我包含的暂停命令,变量设置正确。我还尝试使用如果%WINVERSION%==%XP%goto XPTRUE/

我正在编写一个批处理脚本,以使用USMT将计算机从XP更新到7。因为USMT有一个在OS升级之前需要运行的scanstate组件和一个在OS升级之后必须运行的loadstate计算机,所以我尝试使用if语句来检查操作系统是什么,然后运行正确的命令。我是新的批处理文件,但从我一直在阅读的一切,似乎我写得很好,但我显然搞砸了某个地方。我得到一个“Windows此时出现意外错误”。我还知道,由于我包含的暂停命令,变量设置正确。我还尝试使用
如果%WINVERSION%==%XP%goto XPTRUE/WIN7TRUE
,并将所有内容括在
:XPTRUE/WIN7TRUE
下的括号中,但这会产生相同的错误

::Don't have commands print...only outputs are printed
@echo off
:: Set constants
SET XP=Microsoft Windows XP [Version 5.1.2600]
SET WIN7=Microsoft Windows [Version 6.1.7601]
SET XPUSMTLOCATION=C:\Program Files\USMT\Binaries\v4\x86
SET 7USMTLOCATION=C:\Program Files (x86)\USMT\Binaries\v4\amd64
SET BACKUPLOACTION=\\[SERVER IP]\z$\UserAccountBackUps\Backups
SET LOCALBACKUPLOCATION=C:\Backup\USMT
SET NASBACKUPLOCATION=S:\UserAccountBackUps\Backups
@PAUSE
::Get the current version of Windows batch file is running on and store it in WINVERSION
FOR /f "delims=" %%A IN ('ver') DO @SET WINVERSION=%%A
echo %WINVERSION%
PAUSE
::Get the MAC address of the computer and store it in MACA
FOR /F %%A IN ('getmac') DO @SET MACA=%%A
echo The MAC Address is: %MACA%
:: Tell user about script
echo This is a script designed to migrate computers with one network card from Windows XP to Windows 7 using USMT, this script should not be used with computers that have multiple network cards
echo Xp is %XP%
echo 7 is %WIN7%
::Check to see if the current version is XP
PAUSE

IF %WINVERSION% == %XP% (
echo This is windows XP
::Change directory to the location of USMT files
cd %XPUSMTLOCATION%
::Run scanstate to create backup
scanstate.exe C:\Backup /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigApp.xml" /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigDocs.xml" /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigUser.xml" /o /v:2
::Change directory to the location of where the USMT backup is
cd %LOCALBACKUPLOCATION%
::Rename the backup to the MAC Address
rename USMT.MIG %MACA%.MIG
::Map the NAS to a drive because xcopy can not take IP addresses
echo Mapping NAS to drive
::NAS is mapped to drive S, if S is used for something else change s below to different letter
net use s: \\[SERVER IP]\z$
echo Prepairing to copy backup to NAS
::Use xcopy to transfer backup file the /v ensures the files are identical
::This must be done this way because if USMT tries to backup directly to the NAS it tries to overwrite all existing files
xcopy %LOCALBACKUPLOCATION%\%MACA%.MIG %NASBACKUPLOCATION% /v
echo The copy has completed, run this batch file again after OS Upgrade
)

IF %WINVERSION% == %WIN7% (
echo This is Windows 7
PAUSE
)
当我在Windows 7计算机上运行此操作时,我得到以下信息:

我在我的XP计算机上得到相同的输出,只是它告诉我当前版本是XP。非常感谢您的帮助

下一行:

FOR /f "delims=" %%A IN ('ver') DO @SET WINVERSION=%%A
IF %WINVERSION% == %XP% (
IF "%WINVERSION%" == "%XP%" (
在WINVERSION变量中存储一个字符串,该字符串包含由空格分隔的多个单词,例如:

SET WINVERSION=Microsoft Windows [Version 6.2.9200]
这样,下面的行:

FOR /f "delims=" %%A IN ('ver') DO @SET WINVERSION=%%A
IF %WINVERSION% == %XP% (
IF "%WINVERSION%" == "%XP%" (
扩展到:

IF Microsoft Windows [Version 6.2.9200] == Microsoft Windows XP [Version 5.1.2600] (
当然,这会导致语法错误!键入:
IF/?
以了解更多详细信息

比较可能包含空格的两个字符串的方法是将它们括在引号中: