Batch start or close VMware Services (reprint)

Source: Internet
Author: User
Tags echo command goto microsoft website

VMWare is really a good thing, but after installation there are four more auto-initiated services and two virtual network connections. I hate it when it's all about system resources, not to mention VMware, so I wrote a batch script to automatically start/close VMware VMS and related services and network connections.
The contents of the full batch file are as follows:


1 @echo on
2 @PROMPT [vmwarecontroller]#
3
4 @if "%1" = = "Goto Help
5 @if '%1 ' = = ' help ' goto help
6 @if "%1" = = "/?" Goto Help
7
8 @SET oprtype=%1
9 @SET netopr=%oprtype%
10
One @if "%oprtype%" = = "Start" @SET netopr=enable
@if "%oprtype%" = = "Stop" @SET netopr=disable
13
@SET vmxfile=%2
@Rem If you do not provide a second parameter, VMX full path, you will try to use the default virtual machine set here
@Rem modify this file as needed to the VMX file that you actually want to start
@if "%vmxfile%" = = "@SET vmxfile=d:\vmware\red Hat Enterprise Linux 3.vmx
18
@Rem the installation directory for VMware and modify it as needed
@SET Vmwarefolder=e:\apptool\vmware
21st
@Rem set VMware-related four services to manual
sc config Vmauthdservice start= demand
sc config VMNETDHCP start= demand
sc config "VMware NAT Service" start= demand
-SC config Vmount2 start= demand
27
@Rem Start/stop VMware-related four services
NET%oprtype% "VMware Authorization Service"
NET%oprtype% "VMware DHCP Service"
-Net%oprtype% "VMware NAT Service"
NET%oprtype% "VMware Virtual Mount Manager Extended"
33
@Rem use wildcards here to deactivate/enable all vmnet related network connections
DevCon%netopr% *vmnet*
36
PNS @Rem use Vmrun to run the specified virtual machine
"%vmwarefolder%\vmrun"%oprtype% "%vmxfile%"
39
@goto endmission
41
42:help
@echo automatically start/stop specified VMWare virtual machines and related services and network connections
The @echo requires DevCon tools to control network connections. Tools:
@echo HTTP://SUPPORT.MICROSOFT.COM/KB/311272/ZH-CN
@echo Command-line arguments:
@echo%0 [Start^|stop] ^
@echo ^ The virtual machine configuration file that is started by default
@pause
Goto Endmission
51
52:endmission
View Plain | Print | Copy to Clipboard |?
@echo on
@PROMPT [vmwarecontroller]#

@if "%1" = = "Goto Help
@if '%1 ' = = ' help ' goto help
@if "%1" = = "/?" Goto Help

@SET oprtype=%1
@SET netopr=%oprtype%

@if "%oprtype%" = = "Start" @SET netopr=enable
@if "%oprtype%" = = "Stop" @SET netopr=disable

@SET vmxfile=%2
@Rem If you do not provide a second parameter, the VMX full path will attempt to use the default virtual machine set here
@Rem change this file to the Vmx file that you actually want to start.
@if "%vmxfile%" = = "@SET vmxfile=d:\vmware\red Hat Enterprise Linux 3.vmx

@Rem the installation directory for VMware and modify it as needed
@SET Vmwarefolder=e:\apptool\vmware

@Rem set four VMware-related services to Manual
sc config Vmauthdservice start= demand
sc config VMNETDHCP start= demand
sc config "VMware NAT Service" start= demand
sc config Vmount2 start= demand

@Rem Start/stop VMware-related four services
NET%oprtype% "VMware Authorization Service"
NET%oprtype% "VMware DHCP Service"
NET%oprtype% "VMware NAT Service"
NET%oprtype% "VMware Virtual Mount Manager Extended"

@Rem use wildcard characters here to deactivate/enable all vmnet related network connections
DevCon%netopr% *vmnet*

@Rem use Vmrun to run the specified virtual machine
"%vmwarefolder%\vmrun"%oprtype% "%vmxfile%"

@goto endmission

: Help
@echo automatically start/stop a specified VMWare virtual machine and related services and network connections
@echo need to DevCon tools to control network connections. Tools:
@echo HTTP://SUPPORT.MICROSOFT.COM/KB/311272/ZH-CN
@echo Command-line arguments:
@echo%0 [Start^|stop] ^
@echo ^ Virtual machine configuration files that are started by default
@pause
Goto Endmission

: endmission


Save the above code as a. bat file, and create two shortcuts to the. bat file, and add the Start/stop parameter to the two shortcuts (or you can provide a second parameter to specify that you want to start a specific virtual machine profile), and you can start/stop VMWare directly via a shortcut Related virtual machines and services.

It uses the DevCon tool to control the deactivation/activation of the network connection and needs to download the tool to the Microsoft website.

Note: If there are other hardware IDs in your system that contain *vmnet* strings, all related devices will be disabled/enabled at the same time. You can enter DevCon find *vmnet* at the command line to see if it matches only the two virtual network connections added by VMWare.

When you close a virtual machine with Vmrun, the function is equivalent to the Power off button on the operating interface. It is best to use the shutdown command of the virtual operating system to safely exit the operating system before executing the batch process.

Batch start or close VMware Services (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.