bat 功能脚本

这篇博客包含了多个Windows系统的管理与自动化脚本,包括使用批处理解决Compare秘钥问题,部署和管理Hyper-V,删除空文件夹,实现程序以管理员权限运行,调整虚拟机相关服务状态,部署组策略,以及检查用户权限。这些脚本主要用于提升系统管理和维护的效率。
摘要由CSDN通过智能技术生成

1.Compare秘钥问题

@echo off
echo 开始破解Compare秘钥问题......
set path=C:\Users\Administrator\AppData\Roaming\Scooter Software\Beyond Compare 4
cd %path%
C:
echo 删除问题文件,请输入 Y 进行确认!
del *.*
echo 秘钥问题解决......!
echo. & pausve

2.help-v 相关
2.1部署

pushd "%~dp0"

dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt

for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"

del hyper-v.txt

Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL

2.2启动

bcdedit /set hypervisorlaunchtype auto

2.3关闭

bcdedit /set hypervisorlaunchtype off

3.删除空文件夹

@echo off
setlocal enabledelayedexpansion
del /q %~d0\empty_dir
del /q %~d0\directory.txt
REM 下面的代码加上sort /r ,表示逆序排列文件夹。子文件夹在前,父文件夹在后。
dir /a:d /b /s "."  | sort /r > "%cd%\directory.txt"
for /f "usebackq delims=" %%i in ("directory.txt") do (
    echo "enter dir is: %%i"
    cd "%%i"
    echo "the bat path is: %~f0" rem print this batfile's whole path.
    echo "cur dir is: "%%i""
    REM 将当前目录下的所有文件打印到以下文件中:
    dir /a /b "%%i" >"c:\folder_content.txt"
    echo "======================================================="
    echo "==================fold content: begin ================="
    :type "c:\folder_content.txt"
    echo "==================fold content: end   ================="
    echo "======================================================="
    
    REM 下面的findstr命令查找当前文件是否有内容,如果查找成功表示目录不是空的,否则是空的。
    REM 注意下面的两个 '与' 和 两个 '或' 符号。    
    findstr . "%~d0\folder_content.txt" >nul 2>nul && ( echo "The folder "%%i" is NOT NOT NOT empty") || ( echo "The folder "%%i" is empty" && echo "%%i">>"%cd%\empty_dir" && rd "%%i")
    ::del "%~d0\folder_content.txt"
    )
 ::del  "%cd%\directory.txt" 
 pause

4.自动以管理员权限运行

@echo on  
echo %session%
net.exe session 1>NUL 2>NUL && (
    goto gotAdmin
) || (
    goto UACPrompt
)
   
:UACPrompt  
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" 
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" 
    "%temp%\getadmin.vbs" 
    exit /B  
   
:gotAdmin  
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )  
 
:begin
@echo off
pause

5.启动虚拟机相关权限

sc config VMAuthdService start= demand
sc start VMAuthdService

sc config VMwareHostd start= demand
sc start VMwareHostd

sc config VMUSBArbService start= demand
sc start VMUSBArbService

sc config VMUSBArbService start= demand
sc start VMUSBArbService

sc config VMware NAT Service start= demand
sc start VMware NAT Service
#pause

6.组策略部署

@echo off
pushd "%~dp0"
dir /b %systemroot%\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >gp.txt
dir /b  %systemroot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>gp.txt
for /f %%i in ('findstr /i . gp.txt 2^>nul') do dism /online /norestart /add-package:"%systemroot%\servicing\Packages\%%i"
pause

7.检测当前用户权限

echo off
net.exe session 1>NUL 2>NUL && (
    goto as_admin
) || (
    goto not_admin
)

:as_admin
echo as_admin
goto end

:not_admin
echo not as admin

:end
pause
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值