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
Batch file 批处理文件NewView-错误检查帮助_Batch File - Fatal编程技术网

Batch file 批处理文件NewView-错误检查帮助

Batch file 批处理文件NewView-错误检查帮助,batch-file,Batch File,我创建了以下脚本,以帮助IT人员进行USMT迁移。其目的是列出按日期分类的可用迁移存储,然后使用一系列用户输入菜单选择它们 但问题是,如果用户输入了正确的值,则没有问题;如果输入了错误的值,则脚本将继续,并且目录结构变量中包含错误的值。我曾尝试使用if not exist,但我的代码只是将脚本引入无限循环。如果有人能帮我减轻这些错误,我会很感激的,我是一个基础设施人员,而不是程序员;) 整本 @ECHO OFF :START :MIGSERVER cls ECHO. ECHO ________

我创建了以下脚本,以帮助IT人员进行USMT迁移。其目的是列出按日期分类的可用迁移存储,然后使用一系列用户输入菜单选择它们

但问题是,如果用户输入了正确的值,则没有问题;如果输入了错误的值,则脚本将继续,并且目录结构变量中包含错误的值。我曾尝试使用if not exist,但我的代码只是将脚本引入无限循环。如果有人能帮我减轻这些错误,我会很感激的,我是一个基础设施人员,而不是程序员;)

整本

@ECHO OFF
:START

:MIGSERVER
cls
ECHO.
ECHO ____________________________________________________________
ECHO Please set the deployment server
ECHO For example: UKHQITS017 FRPRAPS002 HUHKAPS001 etc
ECHO.
ECHO By default this script is configured to use the reminst 
ECHO share for USMT migrations.
ECHO ____________________________________________________________
ECHO.
Set /P MigServer=Please enter USMT Server:
cls
ECHO Server set to: %migserver% 
ECHO Please insure this is correct before continuing
pause
cls
GOTO MENU:

:MENU
ECHO.
ECHO ________________________________________________
ECHO User State Migration Tool v0.1
ECHO ________________________________________________
ECHO.
ECHO 1 Check Directory parameters
ECHO 2 Set USMT Server
ECHO 3 Delete Unused User Profiles (XP ONLY)
ECHO 4 Export migration settings from host system (Windows XP 32Bit)
ECHO 5 Export migration settigns to target system (Windows 7 32Bit)
ECHO 6 Exit
ECHO.
SET /P userChoice=Choose Option(1-6):

IF %userchoice% == 1 GOTO DIRPARAMS
IF %userchoice% == 2 GOTO MIGSERVER
IF %userchoice% == 3 GOTO PROFDEL
IF %userchoice% == 4 GOTO SCANSTATEXP32
IF %userchoice% == 5 GOTO LOADSTATEW732
IF %userchoice% == 6 GOTO QUITMENU


:DIRPARAMS
cls
ECHO.
ECHO  Current USMT x86 Folder: %CD%
ECHO  Current USMT Migration Store Server: %migserver%
ECHO.
ECHO   Please make sure of the following
ECHO   before continuing.
ECHO.
ECHO   1. You have set the correct migration server in the batch file.
ECHO   2. The above directorys exist
ECHO   3. The appropriate files are included within them
ECHO.
pause
cls
GOTO MENU:

:PROFDEL
cls
ECHO User Profile Deletion - Please select which profiles you wish to remove.
"%CD%\delprof2.exe" -c:127.0.0.1 -p -d:90
ECHO.
pause
GOTO MENU:

:SCANSTATEXP32
cls
ECHO Creating migration store.......
"%CD%\scanstate.exe" "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%date%" /o /c /i:userfiles.xml /i:migapp.xml /v:12
ECHO.
pause
GOTO MENU:

:LOADSTATEW732
cls
dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%" 
Set /P loadstateday=Please enter day(01-31):
cls
dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%" 
Set /P loadstatemonth=Please enter month(01-12):
cls
dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%\%loadstatemonth%"
Set /P loadstateyear=Please enter year(Example 2011):
cls
ECHO You have selected: Day: %loadstateday% Month: %loadstatemonth% Year: %loadstateyear%
ECHO.
Set /P loadstateset=Are these settings correct? (Enter Yes/No):
IF %loadstateset% == Yes GOTO LOADSTATEGO
IF %loadstateset% == Y GOTO LOADSTATEGO
IF %loadstateset% == NO GOTO LOADSTATEW732
IF %loadstateset% == N GOTO LOADSTATEW732

:LOADSTATEGO
ECHO Exporting Migration Settings...
"%CD%\loadstate.exe" \\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%Loadstateday%\%Loadstatemonth%\%Loadstateyear% /c /i:userfiles.xml /i:migapp.xml /v:12
ECHO.
pause
GOTO MENU:

:QUITMENU
ECHO USM TOOL v0.1 has ended.
pause

可以对其使用IF-EXIST命令。但是,IF-EXIST的标准语法仅适用于文件。此处引用: 您可以按如下方式构造它:

:LOADSTATEW732
cls
dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%" 
Set /P loadstateday=Please enter day(01-31):
cls
IF EXIST "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%\NUL" (
 GOTO MONTH
) ELSE (
 ECHO Not a valid day integer.
 PAUSE
 GOTO LOADSTATEW732
)
:MONTH
cls
dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%" 
Set /P loadstatemonth=Please enter month(01-12):
cls
IF EXIST "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%\%loadstatemonth%\NUL" (
 GOTO YEAR
) ELSE (
 ECHO Not a valid month integer.
 PAUSE
 GOTO MONTH
)

诸如此类。

感谢您的回复,但您的代码仍然存在原始问题。如果用户输入(比如)25,您的代码将验证其正确性并转至月份,但是,如果UNC路径中不存在25,它将崩溃,因为它试图在不存在的文件夹上执行DIR。此外,不确定您这样做是否是偶然的,但您的脚本中有2个标记实例:LOADSTATEW732。一个在开头,一个在结尾。每个GOTO标记必须是唯一的。实际上,正如您现在可以清楚地看到的,这是两个不同的片段。“第一次”出现的
:LOADSTATEW732
是完整脚本摘录的一部分,另一次属于整个脚本。完全忽略了两者之间的“整个脚本”行=/
:LOADSTATEW732
cls
dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%" 
Set /P loadstateday=Please enter day(01-31):
cls
IF EXIST "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%\NUL" (
 GOTO MONTH
) ELSE (
 ECHO Not a valid day integer.
 PAUSE
 GOTO LOADSTATEW732
)
:MONTH
cls
dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%" 
Set /P loadstatemonth=Please enter month(01-12):
cls
IF EXIST "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%\%loadstatemonth%\NUL" (
 GOTO YEAR
) ELSE (
 ECHO Not a valid month integer.
 PAUSE
 GOTO MONTH
)