防火墙例外

@echo off
::设置标题颜色和窗口尺寸
mode con cols=75 lines=25
title=远程桌面端口修改脚本
setlocal EnableDelayedExpansion&color 70 & cd /d "%~dp0"
%1 %2

::管理员权限跳转
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :start","","runas",1)(window.close)&goto :eof

:start
echo.
echo.
echo.
echo.
echo                ----------------------------------------------
echo               |                                            |
echo               |   远程桌面端口修改脚本                     |
echo               |                                            |
echo               |   适用于win2003-win10系统                  |
echo               |                                            |
echo               |   自动添加防火墙规则                       |
echo               |                                            |
echo               |   请输入各自部门预设端口                   |
echo               |                                            |
echo               |   务必检查无误后执行回车                   |
echo               |                                            |
echo                ----------------------------------------------
echo.
echo.
echo.
echo.
echo.
set /p c= 请输入预设端口回车:
if "%c%"=="" goto end
goto edit
:edit

netsh advfirewall firewall add rule name="Remote PortNumber" dir=in action=allow protocol=TCP localport="%c%">nul
netsh advfirewall firewall add rule name="Remote PortNumber" dir=in action=allow protocol=UDP localport="%c%">nul
netsh advfirewall firewall add rule name="3389" dir=in action=block protocol=TCP localport="3389">nul
netsh advfirewall firewall add rule name="3389" dir=in action=block protocol=UDP localport="3389">nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp" /v "PortNumber" /t REG_DWORD /d "%c%" /f>nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v "PortNumber" /t REG_DWORD /d "%c%" /f>nul
echo 修改成功
echo 重启后生效,按任意键重启
pause
shutdown -r -f -t 0
exit
:end
echo 修改失败
pause

过期文件清理

@echo off
set SrcDir=D:\Users\wangzhihao.2024329\Desktop\新建文件夹
REM 指定天数
set DaysAgo=35
forfiles /p %SrcDir% /s /m *.* /d -%DaysAgo% /c "cmd /c del /f /q /a @path"
pause

禁止息屏、睡眠

title 关闭息屏_关闭睡眠
SETX Path ""%SystemRoot%"\system32"
powercfg -x -standby-timeout-ac 0
powercfg -x -monitor-timeout-ac 0
pause

强力删除

文件、文件夹拖放至批处理

DEL /F /A /Q \\?\%1
RD /S /Q \\?\%1

显示计算机信息

@echo off
mode con cols=30 lines=10
title=电脑信息
setlocal ENABLEEXTENSIONS & set "i=0.0.0.0" & set "j="
for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do (
  if not defined j for %%b in (%%a) do set "i=%%b" & set "j=1")
endlocal & set "ip=%i%"
echo.
echo 计算机名:%COMPUTERNAME%
echo 用 户 名:%username%
echo IP 地 址:%ip%
echo.
echo 截图发给IT,方便远程协助
pause
如果觉得我的文章对你有用,请随意赞赏