1

Have a weird issue, firstly am using batch files to install applications..the installations are working fine without any issue.

I have at the end of the batch if the error level is NEQ 0 output the error code to a file, but the output is always 9009.

From searching the web for 9009 it says that the executable cannot be found, but surely it can as the application installs fine.

Here is a sample of one of my batch scripts to install:

  IF exist %windir%\LogFolder\BoxSync4.0x86.txt ( goto eof ) ELSE ( goto BoxSyncInstall     )

  :BoxSyncInstall
  msiexec /i "\\servername\InstallFolder\BoxSync\SyncMSI32.msi" /qn
  if %ErrorLevel% EQU 0 (
  >>"\\servername\gpolog\BoxSync4.0x86.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Box Sync 4.0 x86 Installed"
  >>"%windir%\gpologs\BoxSync4.0x86.txt" echo "Box Sync 4.0 x86 Installed"
  ) 
  else if %ErrorLevel% NEQ 0(
  >>"\\servername\gpolog\BoxSyncErrorsx86.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Error trying to install/upgrade to    BoxSync4.0x86"
  )

  :eof

Does anyone have any ideas why I might be getting this error constantly?

Thanks

Mikoyan

Mikoyan
  • 59
  • 2
  • 8

3 Answers3

3

Try using setlocal enabledelayedexpansion at the start of your batch file, and !ERRORLEVEL! inside your IF.

See also:

Community
  • 1
  • 1
Ilya
  • 4,583
  • 4
  • 26
  • 51
  • 1
    Not an issue here. The ERRORLEVEL was set prior to entering the IF block, so delayed expansion not needed. – dbenham Jun 03 '14 at 12:31
2

The problem is syntax, you need a space between your 0 and (, like so:

IF exist %windir%\LogFolder\BoxSync4.0x86.txt ( goto eof ) ELSE ( goto BoxSyncInstall     )

:BoxSyncInstall
msiexec /i "\\servername\InstallFolder\BoxSync\SyncMSI32.msi" /qn
if %ErrorLevel% EQU 0 (
>>"\\servername\gpolog\BoxSync4.0x86.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Box Sync 4.0 x86 Installed"
>>"%windir%\gpologs\BoxSync4.0x86.txt" echo "Box Sync 4.0 x86 Installed"
) 
else if %ErrorLevel% NEQ 0 (
>>"\\servername\gpolog\BoxSyncErrorsx86.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Error trying to install/upgrade to    BoxSync4.0x86"
)

:eof

EDIT: If the installer needs admin privileges and this is a Win8+ OS, you might have security restrictions, in that case, copy the msi installer into the %TEMP% folder and run it from there. The reason this happens is because when you run the command prompt in Administrator mode, it restricts use of unc paths (for "security" reasons).

Try also pushd and popd as @dbenham keeps reminding us: LINK

Community
  • 1
  • 1
Alex
  • 917
  • 5
  • 11
  • Thanks I changed the script but it still putputs a successful file (EQU 0) yet still an error file with 9009 – Mikoyan Jun 03 '14 at 09:44
  • 1
    @Mikoyan - Also, ELSE must be on the same line as the prior closing parenthesis. Read the documentation. Enter `help if` or `if /?` from the command prompt. – dbenham Jun 03 '14 at 12:30
1

found where the issue lied it is under the ELSE IF as I watched the install script run by not being silent.

After removing ELSE the script ran fine. Thanks again for your help as you have guided me with other tricks.

Mikoyan
  • 59
  • 2
  • 8
  • Could you please explain more detailing, why removing of ELSE helped you? – Ilya Jun 03 '14 at 13:26
  • 1
    Hi llya, when I viewed the script it said invalid syntax for: else if %ErrorLevel% NEQ 0. I then removed the if %errorlevel% NEQ 0 and just added else ( >>"\\servername\gpolog$\BoxSyncErrorsx86.csv" echo %computername%,%date% - %time%,%ErrorLevel%,"Error trying to install/upgrade to BoxSync4.0x86" ) :eof – Mikoyan Jun 05 '14 at 10:39