本帖最后由 lookat 于 2023-7-22 20:26 编辑
虽然可以说这玩意都是换汤不换药查重率估摸着也得70%,但整体还是自己的包括注册表中寻找地址的再运行的这种偷懒想法(自己用的挺流畅)。
主要是吧,不想开机启动,又懒得去服务里手动。
[Bash shell] 纯文本查看 复制代码 @echo off
setlocal EnableDelayedExpansion
color 3e
title 请授权管理员模式
PUSHD %~DP0 & cd /d "%~dp0"
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close) & goto :eof & exit
:runas
set /a ap = 0
set vmd=VMnetDHCP
set vmas=VMAuthdService
set vmus=VMUSBArbService
set vmns=VMware NAT Service
set stopSv=停止指令
set startSv=启动指令
set noSv=未执行
set charText=##################################################
set charText2=#################################
set charText3=## ##
set dhcp=%vmd% %startSv%
set authd=%vmas% %startSv%
set usbarb=%vmus% %startSv%
set nat=%vmns% %startSv%
set dhcps=%vmd% %stopSv%
set authds=%vmas% %stopSv%
set usbarbs=%vmus% %stopSv%
set nats=%vmns% %stopSv%
set vmNoService=未检测到VM服务已自动取消 按任意键关闭...
set vmOver=VMware服务操作执行完成 按任意键关闭...
sc query %vmas% > nul && cls && goto head3 || goto noService
:head3
echo %charText2%
echo %charText2%
echo %charText3%
echo ## %vmd% ##
echo ## %vmas% ##
echo ## %vmus% ##
echo ## %vmns% ##
echo %charText3%
echo %charText2%
echo %charText2%
echo %charText3%
echo ## 1 启动服务 ##
echo ## 2 停止服务 ##
echo %charText3%
echo ## 额外输入自动检查 ##
echo ## 并启动或停止服务 ##
echo %charText3%
echo %charText2%
echo %charText2%
echo %charText3%
echo ## 请输入1或2 ##
echo %charText3%
if %ap% equ 0 (goto input3) else (goto body3)
:input3
::Rem CHOICE /C 123 /N /T 10 /D 3 /M "请输入1或2" %ERRORLEVEL% ;选项1,2,3 ;隐藏多余提示;10秒自动选择3;提示语;取值
set /p ap=
cls
goto head3
:body3
echo %charText3%
echo ## 已输入 %ap:~0,1% ##
echo %charText3%
echo %charText2%
echo %charText2%
if %ap:~0,1% equ 1 (goto startService) else if %ap:~0,1% equ 2 (goto stopService) else (goto scService)
:startService
echo %charText%
net start %vmd% && echo %dhcp% || echo %dhcp%%noSv%
echo %charText%
net start %vmas% && echo %authd% || echo %authd%%noSv%
echo %charText%
net start %vmus% && echo %usbarb% || echo %usbarb%%noSv%
echo %charText%
net start "%vmns%" && echo %nat% || echo %nat%%noSv%
echo %charText%
goto setVMhost
:stopService
echo %charText%
net stop %vmd% && echo %dhcps% || echo %dhcps%%noSv%
echo %charText%
net stop %vmas% && echo %authds% || echo %authds%%noSv%
echo %charText%
net stop %vmus% && echo %usbarbs% || echo %usbarbs%%noSv%
echo %charText%
net stop "%vmns%" && echo %nats% || echo %nats%%noSv%
echo %charText%
goto exit_this
:scService
echo %charText%
sc query %vmd% && net stop %vmd% && echo %dhcps% || net start %vmd% && echo %dhcp%
echo %charText%
sc query %vmas% && net stop %vmas% && echo %authds% || net start %vmas% && echo %authd%
echo %charText%
sc query %vmus% && net stop %vmus% && echo %usbarbs% || net start %vmus% && echo %usbarb%
echo %charText%
sc query "%vmns%" && net stop "%vmns%" && echo %nats% || net start "%vmns%" && echo %nat%
echo %charText%
sc query %vmd% && goto exit_this || goto setVMhost
:noService
echo;
echo %vmNoService%
pause >nul
exit
:setVMhost
set vmHost="HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware Drivers" /v "VMnetuserif.installPath"
reg query %vmHost% >nul 2>nul&&echo 检测到VM路径 && goto startExe||echo 未检测到VM安装路径 && goto exit_this
:startExe
set nameExe=vmware.exe
for /f "skip=1 delims=: tokens=1,*" %%i in ('reg query %vmHost%') do (
set str=%%i
set var=%%j
set "var=!var:"=!"
if not "!var:~-1!"=="=" set value=!str:~-1!C:!var!
)
set openExe="%value:~1,-15%%nameExe%"
start /min cmd /C %openExe%
ping -n 3 127.0.0.1 > nul
tasklist | find /i "VMware Workstation" && echo 打开路径 %openExe:~1,-1% || echo %openExe:~1,-1% 请手动打开VMWare虚拟机
goto exit_this
:exit_this
echo;
echo %vmOver%
for /l %%c in (0 1 12) do ( echo; )
pause >nul
rem ping -n 7 127.0.0.1 > nul
taskkill /F /IM cmd.exe
exit
加了好几样懒方法和识别后台服务,但貌似还是会重复启动vm的窗口。
反正难度不大就当改卷子
文本文件改bat格式 |