一大堆学习过程中产生的临时脚本,涉及到搜索文件的功能、查询注册表或者执行systeminfo命令获取系统版本的功能,可以学习for的用法等。
@echo off ipconfig /al >> log.txt 2>&1 pause exit rem 网友给的解决方案 for %%i in (c: d: e:) do ( pushd %%i for /r %%j in (ospp.vbs) do if exist %%j echo %%j) pause exit for %%i in (c: d: e: f:) do ( pushd %%i dir /a-d /b /s ospp.vbs ) pause exit FOR /F "tokens=1,2,* delims= " %%i in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe" /v "Path"') do FOR /F "tokens=1-5 delims=\\" %%l in ("%%k") do echo %%o echo %Name% pause exit rem 行不通,闪退 for %%i in (c:\ d:\ e:\) do for /r %%i %%j in (ospp.vbs) do if exist %%j echo %%j pause exit for /r c:\ %%i in (ospp.vbs) do if exist %%i echo %%i else echo none pause exit FOR /F "tokens=1,2,* delims= " %%i in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "ProductName"') do set Name=%%k echo %Name% goto Windows Server 2012 Datacenter goto def :Windows Server 2012 Datacenter echo abc123 pause exit :def echo def pause exit rem 方法二,成功 FOR /F "tokens=1,* delims=:" %%i in ('systeminfo') do if {"%%i"}=={"OS 名称"} set Name=%%j rem 清除字符串中所有空格 set "Name=%Name: =%" echo %Name% pause exit rem 方法三,成功 FOR /F "tokens=1,* delims=:" %%i in ('systeminfo') do ( if {"%%i"}=={"OS 名称"} ( for /f "tokens=*" %%k in ("%%j") do set "name=%%k" ) ) echo,%name% pause>nul exit rem 方法一,成功 rem 第二个for为了清除截取到的字符串前面的空格 FOR /F "tokens=1,* delims=:" %%i in ('systeminfo') do if {"%%i"}=={"OS 名称"} for /f "tokens=* delims= " %%l in ("%%j") do set Name=%%l echo %Name% pause exit REG QUERY HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion | find /i "EFS" 1>nul if ERRORLEVEL 1 echo error echo succ pause exit systeminfo 2>nul | find /i "Microsoft Windows Server 2012 Standard" && echo 成功地激活了产品。 systeminfo 2>nul | find /i "Microsoft Windows Server 2012 Datacenter" && echo 成功地激活了产品。 systeminfo 2>nul | find /i "Microsoft Windows Server 2012 R2 Datacenter" && echo 成功地激活了产品。 systeminfo 2>nul | find /i "Microsoft Windows 8 专业版" && echo 成功地激活了产品。 systeminfo 2>nul | find /i "Windows 8 Enterprise" && echo 成功地激活了产品。 pause