This is probably nothing to most but may be helpful to someone else who also is/was struggling.
Debugging, why a script I have written, when run from a file via the Windows shell, it works just great but when run via ZENworks bundle, “Run Script=>Define your own script” section, it yields the message:
“The syntax of the command is incorrect.”
It turns out that within the nested ‘IF’ statement, ZENworks is dropping one of the FOR loop variable’s double ‘%’ characters, which causes ‘IF’, to throw the syntax error.
I managed to slow the processor down enough by putting another batch file into an endless loop.
I was then able to make a copy of the script that ZENworks is writing to the %TEMP% directory, before ZENworks executes and deletes it.
That way I could then see what ZENworks was doing in the background.
I used the Sysinternals Process Monitor utility to discover where ZENworks was writing this file.
This snippit of code works, when manually run from the Windows shell, but fails as a bundle:
for /f "tokens=1* delims==" %%A in ('wmic baseboard get /format:list ^| find "="') do ( if "%%A"=="SerialNumber" set __BASE_SN=%%B )
This is the batch file written by ZENworks into %TEMP% when the bundle is launched. It is virtually the same, except within the ‘IF’ statement, it should have %%A and %%B, which is the reason, ‘IF’ is throwing the syntax error.
for /f "tokens=1* delims==" %%A in ('wmic baseboard get /format:list ^| find "="') do ( if "%A"=="SerialNumber" set __BASE_SN=%B )
The work around for the problem is to define the batch to look like this:
for /f "tokens=1* delims==" %%A in ('wmic baseboard get /format:list ^| find "="') do ( if "%%%A"=="SerialNumber" set __BASE_SN=%%%B )
The bundle writes this code to appear correctly ( with just %% ) and therefore executes it without syntax errors. You need only ‘escape’ the ‘%’ within the ‘IF’ statement.
Unfortunately, this code fails with the same syntax error when run from a file via the Windows shell.
ZCM=22.214.171.124 ZAM=126.96.36.19935 ZPM=188.8.131.52 ZESM=184.108.40.20635 ZFDE=220.127.116.1135
Windows XP SP3 x32:
Windows 7 SP1 x64:
ZENworks 18.104.22.16891 Monthly Update 1 and 22.214.171.12459