psexec batch file

J

Joey

I need to create a batch file that will check the version of the host and
then run an executable from the network...

@echo off
psexec @hosts.txt -u domain\user-p xxxx ver | find "5.2" > nul
if %ERRORLEVEL% == 0 goto ver_2003
if %ERRORLEVEL% == 1 goto ver_XP

:ver_2003
echo Windows 2003
\\server2\setup.exe
goto exit

:ver_XP
echo XP
\\server1\setup.exe
goto exit

Does anyone have any recommendation on how to proceed? psexec is reporting
back "ver" is unknown

thanks
 
T

Tim Meddick

Joey,
The command to execute must be: "cmd /c ver" not "ver" so your
batch script should read:

----------------- copy between lines -----------------
@echo off
psexec @hosts.txt -u domain\user-p xxxx cmd /c ver | find "5.2" > nul
if %ERRORLEVEL%] == 0] goto ver_2003
if %ERRORLEVEL%] == 1] goto ver_XP

:ver_2003
echo Windows 2003
\\server2\setup.exe
goto EOF

:ver_XP
echo XP
\\server1\setup.exe
goto EOF

----------------- copy between lines -----------------


==


Cheers, Tim Meddick, Peckham, London.
 
T

Tim Meddick

Joey,
Sorry, I ALMOST got that right!! Two minor errors: 1). the
ERRORLEVEL statements are listed in the wrong order. If the test for 0 is
before the test for 1 then ) will ALWAYS be found and will always go to Win
2K3! and 2). the EOF (end of file) label should have a colon before it (my
bad).

----------------- copy between lines -----------------
@echo off
psexec @hosts.txt -u domain\user-p xxxx cmd /c ver | find "5.2" > nul
if %ERRORLEVEL%] == 1] goto ver_XP
if %ERRORLEVEL%] == 0] goto ver_2003

:ver_2003
echo Windows 2003
\\server2\setup.exe
goto :EOF

:ver_XP
echo XP
\\server1\setup.exe
goto :EOF

----------------- copy between lines -----------------




==


Cheers, Tim Meddick, Peckham, London.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top