I am unsure why InstallResult always returns a 1 in my VBScript. I have put an echo in my batch file to confirm if I delete the source file before a copy it returns a 4 and that it returns nothing if it is successful. Any help would be appreciated. My files should do the following:
- Copy a script from a network share to the local machine.
- Run a batch file to install office (currently some test code for error checking). The batch file should run and post an error code on exit or a 0 if successful.
- Go back to the VBScript to error check and run another cleanup VBScript.
Here is my code:
Run install 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