我不确定为什么InstallResult
总是在我的VBScript中返回1。我在我的批处理文件中放了一个echo来确认我是否在复制它之前删除了源文件它返回4并且如果成功则不返回任何内容。任何帮助,将不胜感激。我的文件应该执行以下操作:
这是我的代码:
运行安装bat(VBScript)
Dim objshell, InstallResult
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "\\altirisdata\AssetMgmt\Tools\WSM\DeleteOffice13Package.vbs", "C:\source\DeleteOffice13Package.vbs"
'DeleteMS2013FilePath = objShell.run ("c:\source\DeleteOffice13Package.vbs", 0, True)
WScript.Sleep 3000
Set objShell = WScript.CreateObject("WScript.Shell")
InstallResult = objShell.run ("cscript.exe C:\source\Microsoft_Office_2013_01\install.bat", 0, True)
WScript.Echo InstallResult
If InstallResult <> 0 Then WScript.Echo "Unable to install Microsoft Office 2013. Please manually check the install results"
If InstallResult = 0 Then
DeleteDelScript = objShell.Run("cscript.exe c:\source\DeleteOffice13Package.vbs", 0, True)
End If
If DeleteDelScript = 0 Then
FSO.DeleteFile("C:\source\DeleteOffice13Package.vbs")
End If
Set FSO = nothing
WScript.Quit
INSTALL.BAT
@echo off
xcopy "C:\source\test again\test.txt" "C:\Temp\Temp1\TempTest" /y
if %errorlevel% neq 0 (
exit /b %errorlevel%
)
exit
答案 0 :(得分:1)
您的返回值为1,因为您尝试使用 VBScript 解释程序运行批处理脚本:
InstallResult = objShell.run ("cscript.exe C:\sourc...l.bat", 0, True)
从命令行中删除cscript.exe
,或将其替换为%COMSPEC% /c
:
InstallResult = objShell.run ("%COMSPEC% /c C:\sourc...l.bat", 0, True)
作为旁注,您不应该在批处理脚本中需要一个条件。只需返回errorlevel即可:
@echo off
xcopy "C:\source\test again\test.txt" "C:\Temp\Temp1\TempTest" /y
exit /b %errorlevel%