add hvswitch.cmd
This commit is contained in:
parent
820b9e29b7
commit
d2cf0b2a39
16
README.md
16
README.md
|
@ -1,21 +1,23 @@
|
||||||
# template-cmd
|
# Tweaks for Windows
|
||||||
Repository description
|
Tools for managing Windows setting
|
||||||
|
|
||||||
* [`script`](https://git.hmp.today/pavel.muhortov/template-cmd#script)
|
* [`hvswitch`.cmd](https://git.hmp.today/pavel.muhortov/tweaks-for-windows#hvswitch-cmd)
|
||||||
|
|
||||||
____
|
____
|
||||||
## `script`
|
## `hvswitch`.cmd
|
||||||
**Description:** Script description
|
**Description:** Microsoft Hyper-V switch on/off
|
||||||
**Dependencies:** Windows (tested version 10.0.19043)
|
**Dependencies:** Windows (tested version 10.0.19043)
|
||||||
|
|
||||||
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
||||||
|-----------|--------------|------------------------|---------------|
|
|-----------|--------------|------------------------|---------------|
|
||||||
| 1 | **qn** |execution without pauses| `None` |
|
| 1 | **[qn]** |execution without pauses| `None` |
|
||||||
|
| 2 | **[y]** |enable Hyper-V, if it off| `None` |
|
||||||
|
| 2 | **[n]** |disable Hyper-V, if it on| `None` |
|
||||||
|
|
||||||
|
|
||||||
Example usage in terminal:
|
Example usage in terminal:
|
||||||
```cmd
|
```cmd
|
||||||
.\script.cmd qn
|
.\hvswitch.cmd qn y
|
||||||
```
|
```
|
||||||
|
|
||||||
____
|
____
|
||||||
|
|
65
hvswitch.cmd
Normal file
65
hvswitch.cmd
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
pushd "%~dp0"
|
||||||
|
@echo off
|
||||||
|
goto :Start
|
||||||
|
|
||||||
|
--------------------------------------------------
|
||||||
|
Microsoft Hyper-V switch on/off
|
||||||
|
|
||||||
|
Positional parameters:
|
||||||
|
[1] qn - execution without pauses
|
||||||
|
[2] y - enable Hyper-V, if it off
|
||||||
|
n - disable Hyper-V, if it on
|
||||||
|
|
||||||
|
--------------------------------------------------
|
||||||
|
|
||||||
|
:Start
|
||||||
|
set choice=%~2
|
||||||
|
|
||||||
|
:Admin_Check
|
||||||
|
net session >nul 2>&1
|
||||||
|
if %errorLevel% == 0 (
|
||||||
|
set code=0
|
||||||
|
) else (
|
||||||
|
set code=5
|
||||||
|
cls
|
||||||
|
echo Restart this as Administrator!
|
||||||
|
goto :Exit
|
||||||
|
)
|
||||||
|
|
||||||
|
:HV_Check
|
||||||
|
bcdedit /enum | FINDSTR /IL "hypervisorlaunchtype" | FINDSTR /IL "auto"
|
||||||
|
if %errorLevel% EQU 0 (
|
||||||
|
set state=auto
|
||||||
|
) else (
|
||||||
|
set state=off
|
||||||
|
)
|
||||||
|
|
||||||
|
:HV_Choice
|
||||||
|
cls
|
||||||
|
if "%choice%" EQU "y" (
|
||||||
|
if "%state%" EQU "auto" goto :Exit
|
||||||
|
goto :HV_enable
|
||||||
|
)
|
||||||
|
if "%choice%" EQU "n" (
|
||||||
|
if "%state%" NEQ "auto" goto :Exit
|
||||||
|
goto :HV_disable
|
||||||
|
)
|
||||||
|
set /p choice= Do you need a Hyper-V enabled? [y or no]:
|
||||||
|
goto :HV_Choice
|
||||||
|
|
||||||
|
:HV_enable
|
||||||
|
echo Hyper-V enabled...
|
||||||
|
bcdedit /set hypervisorlaunchtype auto
|
||||||
|
shutdown -r -f -t 5 -c "After 5 seconds, the computer will restart"
|
||||||
|
goto :Exit
|
||||||
|
|
||||||
|
:HV_disable
|
||||||
|
echo Hyper-V disabled...
|
||||||
|
bcdedit /set hypervisorlaunchtype off
|
||||||
|
shutdown -r -f -t 5 -c "After 5 seconds, the computer will restart"
|
||||||
|
goto :Exit
|
||||||
|
|
||||||
|
:Exit
|
||||||
|
if "%~1" NEQ "qn" pause
|
||||||
|
popd
|
||||||
|
exit %code%
|
Loading…
Reference in New Issue
Block a user