Equivelent of "On Error Resume Next" for DOS batch...

In VB Scripts you can supress and resume errors by using "On Error Resume Next".  How can you do that in a DOS batch file?

I have a script that shuts down virtual servers in VMware for backup purposes, but if the virtual server is already shutdown, I get an error, and it won't move on to the next server....Here's my script:

-------
call vmware-cmd "C:\Virtual Machines\SERVER1\Windows Server 2003 Standard Edition.vmx" stop

call vmware-cmd "C:\Virtual Machines\SERVER2\Windows Server 2003 Standard Edition.vmx" stop
-------


Is it possible to resume on errors in DOS?

Thanks.
LVL 6
trippleO7Asked:
Who is Participating?
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.

sirbountyCommented:
Hmm - you can reference the error by using

if %errorlevel%==0
which indicates 'no' error...

what's in vmware-cmd?
trippleO7Author Commented:
Here's the syntax of "vmware-cmd" if that's what you mean...

C:\VMware\VMware Server>vmware-cmd
Usage: C:\VMware\VMware Server\vmware-cmd <options> <vm-cfg-path> <vm-action> <arguments>
       C:\VMware\VMware Server\vmware-cmd -s <options> <server-action> <arguments>

  Options:
    Connection Options:
       -H <host>       specifies an alternative host (if set, -U and -P must also be set)
       -O <port>       specifies an alternative port
       -U <username>   specifies a user
       -P <password>   specifies a password
    General Options:
       -h More detailed help.
       -q Quiet. Minimal output
       -v Verbose.

  Server Operations:
    C:\VMware\VMware Server\vmware-cmd -l
    C:\VMware\VMware Server\vmware-cmd -s register <config_file_path>
    C:\VMware\VMware Server\vmware-cmd -s unregister <config_file_path>
    C:\VMware\VMware Server\vmware-cmd -s getresource <variable>
    C:\VMware\VMware Server\vmware-cmd -s setresource <variable> <value>

  VM Operations:
    C:\VMware\VMware Server\vmware-cmd <cfg> getconnectedusers
    C:\VMware\VMware Server\vmware-cmd <cfg> getstate
    C:\VMware\VMware Server\vmware-cmd <cfg> start <powerop_mode>
    C:\VMware\VMware Server\vmware-cmd <cfg> stop <powerop_mode>
    C:\VMware\VMware Server\vmware-cmd <cfg> reset <powerop_mode>
    C:\VMware\VMware Server\vmware-cmd <cfg> suspend <powerop_mode>
    C:\VMware\VMware Server\vmware-cmd <cfg> setconfig <variable> <value>
    C:\VMware\VMware Server\vmware-cmd <cfg> getconfig <variable>
    C:\VMware\VMware Server\vmware-cmd <cfg> setguestinfo <variable> <value>
    C:\VMware\VMware Server\vmware-cmd <cfg> getguestinfo <variable>
    C:\VMware\VMware Server\vmware-cmd <cfg> getid
    C:\VMware\VMware Server\vmware-cmd <cfg> getpid
    C:\VMware\VMware Server\vmware-cmd <cfg> getproductinfo <prodinfo>
    C:\VMware\VMware Server\vmware-cmd <cfg> connectdevice <device_name>
    C:\VMware\VMware Server\vmware-cmd <cfg> disconnectdevice <device_name>
    C:\VMware\VMware Server\vmware-cmd <cfg> getconfigfile
    C:\VMware\VMware Server\vmware-cmd <cfg> getheartbeat
    C:\VMware\VMware Server\vmware-cmd <cfg> getuptime
    C:\VMware\VMware Server\vmware-cmd <cfg> getremoteconnections
    C:\VMware\VMware Server\vmware-cmd <cfg> gettoolslastactive
    C:\VMware\VMware Server\vmware-cmd <cfg> getresource <variable>
    C:\VMware\VMware Server\vmware-cmd <cfg> setresource <variable> <value>
    C:\VMware\VMware Server\vmware-cmd <cfg> setrunasuser <username> <password>
    C:\VMware\VMware Server\vmware-cmd <cfg> getrunasuser
    C:\VMware\VMware Server\vmware-cmd <cfg> getcapabilities
    C:\VMware\VMware Server\vmware-cmd <cfg> addredo <disk_device_name>
    C:\VMware\VMware Server\vmware-cmd <cfg> commit <disk_device_name> <level> <freeze> <wait>
    C:\VMware\VMware Server\vmware-cmd <cfg> answer

C:\VMware\VMware Server>






The Error I am getting when I issue my batch file is this:


C:\VMware\VMware Server>call vmware-cmd "C:\Virtual Machines\Windows Server 2003
 Std Shell\Windows Server 2003 Standard Edition.vmx" stop
VMControl error -8: Invalid operation for virtual machine's current state: The requested operation ("stop") could not be completed because it conflicted with the state of the virtual machine ("off") at the time the request was received.  This error often occurs because the state of the virtual machine changed before it received the request.
VMControl error -8: Invalid operation for virtual machine's current state: Make sure the VMware Server Tools are running

Press any key to continue . . .





From what I can tell, it's running the command, but it see's that the Virtual Guest Machine is already off, so it's presenting me with this error, and won't continue on to the next server.

I guess if there's an easy way to convert this batch file to a VB script, I'm all for that too.  I was just going on what little knowledge of scripting I know :D
sirbountyCommented:
You could 'ping' it first...

ping Vmware-PC1
if %errorlevel%==0 goto shutdown
echo Unable to contact virtual PC
goto :eof

:shutdown
call vmware-cmd "C:\Virtual Machines\SERVER1\Windows Server 2003 Standard Edition.vmx" stop


But yes, we can probably convert this to vbs if the above doesn't work..
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

trippleO7Author Commented:
Running this just seemed to close out....

@echo


ping SERVER1_HOSTNAME
if %errorlevel%==0 goto shutdown
echo Unable to contact virtual PC
goto :eof

:shutdown
call vmware-cmd "C:\Virtual Machines\SERVER1\Windows Server 2003 Standard Edition.vmx" stop

call vmware-cmd "C:\Virtual Machines\SERVER2\Windows Server 2003 Standard Edition.vmx" stop

pause

oBdACommented:
As a side note, you do not need to use "call" when running external programs; you only need to use call when calling other batch files.
Other than that, the problem seems to be that vmware-cmd is waiting for you to press a key when it comes back with an error ("Press any key to continue . . .")
Try to add the "-q" to the options, it might get rid of it:

vmware-cmd -q "C:\Virtual Machines\SERVER1\Windows Server 2003 Standard Edition.vmx" stop
vmware-cmd -q "C:\Virtual Machines\SERVER2\Windows Server 2003 Standard Edition.vmx" stop

Or try to simulate the key:
echo | vmware-cmd "C:\Virtual Machines\SERVER1\Windows Server 2003 Standard Edition.vmx" stop
echo | vmware-cmd -q "C:\Virtual Machines\SERVER2\Windows Server 2003 Standard Edition.vmx" stop
sirbountyCommented:
@echo ?

Remove that line...not needed.

I'm not familiar with this vmware-cmd (don't seem to find it on my system).
Did it respond to a ping?

Adjust it this way...

for %%a in (SERVER1 SERVER2) do call :process %%a
goto :eof

:process
ping %1
if not %errorlevel%==0 (
  echo Unable to contact virtual PC
  goto :eof
)

echo. About to shutdown %1
pause
call vmware-cmd "C:\Virtual Machines\%1\Windows Server 2003 Standard Edition.vmx" stop

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
trippleO7Author Commented:
@ oBdA

The vmware-cmd is actually a .bat file included with the VMWare Server 1.0.1 install which triggers a perl script (I think)...sorry, should have mentioned that initially.  So I will need the "call" in my custom batch file.  I also tried the "-q" option without luck.  Correct me if I'm wrong (I'm wrong a lot), but the "Press any key to continue..." may be coming from the "pause" at the end of my file.

@SirBounty
"vmware-cmd" and "vmware-cmd.bat" was located in my C:\VMWare\VMware Server directory.  I'm running VMware Server 1.0.1, not Workstation or ESX versions if that helps.  That last adjustment seemed to work great.

Let me compile the final script and I will post it, and anymore questions I have on it.

trippleO7Author Commented:
Okay, I tested it with every variable I could think of, and it seems to work great.  I'll be using them in conjunction with Backup Exec, so here are my Pre/Post commands to shutdown my Virtual Guests so I can back them up.

Here's my pre-command:

vmware_shutdown.bat
------------------------------
for %%a in (clay-shell clay-altiris) do call :process %%a
goto :eof

:process
ping %1
if not %errorlevel%==0 (
  echo Unable to contact virtual PC
  goto :eof
)

echo. About to shutdown %1

call vmware-cmd "C:\Virtual Machines\Windows Server 2003 Std Shell\Windows Server 2003 Standard Edition.vmx" stop

call vmware-cmd "C:\Virtual Machines\CLAY-Altiris\Windows Server 2003 Standard Edition.vmx" stop




And once the job completes, it will run this post command to get the virtual servers back up and running....

vmware_startup.bat
------------------------------
call vmware-cmd "C:\Virtual Machines\Windows Server 2003 Std Shell\Windows Server 2003 Standard Edition.vmx" start

call vmware-cmd "C:\Virtual Machines\CLAY-Altiris\Windows Server 2003 Standard Edition.vmx" start

trippleO7Author Commented:
Thanks again!!!
sirbountyCommented:
Happy to help - thanx for the grade! :^ )
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
Microsoft DOS

From novice to tech pro — start learning today.