批处理代码示例:
1、复制文件
@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
cd /d %~dp0
set strdate=%date:~0,4%%date:~5,2%%date:~8,2%
set "srcpath=资料%strdate%"
mkdir "%srcpath%\日志" 1>nul 2>nul
:start
call :ColorText 0a "正在执行,请稍后。。。。。。" & echo.
xcopy "%~dp0AOI\log" "%~dp0%srcpath%\AOI日志" /h /s /e /r /i /Y >log.txt
findstr /c:" 0 个文件" /a:0C log.txt && call :ColorText 4e "复制了 0 个文件,请手动拷贝" & echo.
del log.txt
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
2、windows背景色设置
reg add "HKEY_CURRENT_USER\Control Panel\Colors" /v "window" /t "REG_SZ" /d "202 234 206" /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\DefaultColors\Standard" /v "Window" /t "REG_DWORD" /d "caeace" /f
3、删除老文件
@echo off
set SrcDir=D:\img
:: 删掉多少天以前的
set DaysAgo=30
forfiles /p %SrcDir% /d -%DaysAgo% /c "cmd /c del /f /q /a @path && rd /s /q @path"
4、获取管理员
@echo off
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B