how do you determine if a cmd shell executed successful in

if you run a command prompt to execute say psexec, how can you determine if the error code was 0 or not?
i tried
error1="cmd.exe /c ....."
if error1 <>0 then
 msgbox("there was an error")

Open in new window

it doesn't work though so again how do i determine if a cmd shell executed successfully?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

During testing ... if you either (1) put a "pause" at the end of the CMD commands or (2) put something like "echo CMDScriptRan > c:\ItRan.txt" at the end of the CMD commands.

This should tell you if it is executing the CMD script(s). I would probably do (2) then delete the file and remove the echo line from the CMD lines, once it seems to be working correctly.
bbimisAuthor Commented:
well i was wanting to capture the error code if possible. if error is 0 then it was successful if not 0 then it failed
sample batch file that <--- means brief description of action being taken

Echo Off
cd C:\MYBATS  <--- directory where i store my batch file"
net use z: <---"create a map to one of my server shares"
echo Copying started at %date% %time%>>RunTimes.txt <--- notice the date / time stamp being written to a text file
copy z:\*.* /y "copy all my files from mapped drive to the local drive" <--- begin copying files
echo Copying finished at %date% %time%>>RunTimes.txt <--- another date / time stamp
echo Completed Successfully at %date% %time%>>RunTimes.txt <--- final date / time stamp
echo "">>RunTimes.txt <---just writes a blank line to file to separate entries
net use z: /del <--- delete the server share

You end up with a RUNTIMES.TXT file and the following information:

Copying started at Sat 05/05/2018 21:00:01.55
Copying finished at Sat 05/05/2018 21:01:44.30
Completed Successfully at Sat 05/05/2018 21:01:44.30
Copying started at Sun 05/06/2018 21:00:01.87
Copying finished at Sun 05/06/2018 21:01:24.45
Completed Successfully at Sun 05/06/2018 21:01:24.45
Copying started at Mon 05/07/2018 21:00:01.50
Copying finished at Mon 05/07/2018 21:01:36.87
Completed Successfully at Mon 05/07/2018 21:01:36.87
Copying started at Tue 05/08/2018 21:00:01.32
Copying finished at Tue 05/08/2018 21:01:21.92
Completed Successfully at Tue 05/08/2018 21:01:21.92
Copying started at Wed 05/09/2018 21:00:01.66
Copying finished at Wed 05/09/2018 21:01:22.18
Completed Successfully at Wed 05/09/2018 21:01:22.18

and so on and so on....
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

I did some testing then research. Learn something new every day!

This may assist what you are wanting to confirm (see ); specifically his comments at the end "So you can perform other types of tests against the error level, for example, to perform an equality test:
IF %ERRORLEVEL% EQU 1 echo Different!" ... plus others comments on the post itself.

They should give you some ideas how to determine the errorlevel, depending on the complexity of what you are running.
bbimisAuthor Commented:
so how do you do it in

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbimisAuthor Commented:
This gave me what i needed. Thanks for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.