Avatar of ivan rosa
ivan rosaFlag for United States of America

asked on 

confirmation on batch script

Hello colleagues,

I have this one script to install firefox
psexec @clients.txt "c:\updates\firefox.exe" -ms 

Open in new window


however how would I translate and integrate the following idea?
result=0
if  error code==0 then %result%=success else %result%=failed >>%client%,%result%.csv

Open in new window


so I can get an output like this
User generated image
of if anybody has a better idea would also work?
Windows BatchScripting Languages

Avatar of undefined
Last Comment
ivan rosa
Avatar of NVIT
NVIT
Flag of United States of America image

psexec @clients.txt "doit.bat"

Open in new window

doit.bat
set resultfile=\\server\share\firefoxrslt.csv
"c:\updates\firefox.exe" -ms 
if errorlevel 0 then (
  echo %computername%,success>>%resultfile%
) else (
  echo %computername%,failed>>%resultfile%
)

Open in new window

Avatar of ivan rosa
ivan rosa
Flag of United States of America image

ASKER

I just tried but it gave me an error,

PsExec could not start doit.bat on computer1

if I did doit.bat itself then will start the installation on the computer trying to launch it

and yet even though it gave me an error I didn't get any results...
Avatar of NVIT
NVIT
Flag of United States of America image

psexec @clients.txt -c -f "doit.bat"

Open in new window

Avatar of NVIT
NVIT
Flag of United States of America image

if you do this in a cmd window:
"c:\updates\firefox.exe" -ms
echo %errorlevel%

Open in new window

...one of the the IF lines should be true.
Avatar of ivan rosa
ivan rosa
Flag of United States of America image

ASKER

we got passed the install now, although the result is still not showing up...
Avatar of NVIT
NVIT
Flag of United States of America image

Can it see firefox.exe? Move it to a share...
set resultfile=\\server\share\firefoxrslt.csv
"\\server\share\updates\firefox.exe" -ms 
if errorlevel 0 then (
  echo %computername%,success>>%resultfile%
) else (
  echo %computername%,failed>>%resultfile%
)

Open in new window

Avatar of Bill Prew
Bill Prew

I didn't think firefox.exe returned negative errorlevel's, so won't this always be true?

if errorlevel 0 then (

~bp
Avatar of ivan rosa
ivan rosa
Flag of United States of America image

ASKER

firefox returns 0 for success and other than that is a failed unless if is directly from a psexec command will give something like 1xxx

so I just recreated something else again and this actually writes a file but the content is not quiet there yet

commander
for /f %%a in (clients.txt) do doit.cmd %%a

Open in new window


doit
"c:\updates\firefox.exe" -ms 
if %ERRORLEVEL% EQU 0 echo.%%a,success>>result.csv
if %ERRORLEVEL% NEQ 0 echo.%%a,failed>>result.csv

Open in new window


although the result it gives me is

and it doesn't collect the actual computer name from the variable...
%a      success
%a      success
Avatar of Bill Prew
Bill Prew

Try this, the %%a gets passed to doit.bat as the first command line parm, so is referenced in doit.bat as %1.

"c:\updates\firefox.exe" -ms 
if %ERRORLEVEL% EQU 0 (
  echo.%1,success>>result.csv
) else (
  echo.%1,failed>>result.csv
)

Open in new window

~bp
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Let me suggest an alternative solution that is far more expansive and easier... while not free, it's very inexpensive and no long term commitment (though I think HIGHLY worth the price).

Try Ninite - www.ninite.com - the Pro version can be scripted and also deploy to machines it finds in AD all at once.
SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of ivan rosa
ivan rosa
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of ivan rosa
ivan rosa
Flag of United States of America image

ASKER

never found the right answer...
Scripting Languages
Scripting Languages

A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.

30K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo