列目录功能的batch脚本(在对于要显示的内容非常多的情况下,一下这种方式是非常快速和有用的):
@echo off (For /r D: %%a in (*) do echo %%~ta %%~za %%~fa)>list.txt start list.txt
用批处理获取今天是星期几
@ECHO OFF FOR /F "tokens=*" %%A IN ('DATE /T') DO FOR %%B IN (%%A) DO SET Today=%%B ECHO It's %Today% today. >week_date.bat It's 周五 today. >date /T 2014/08/08 周五
利用systeminfo命令查看未安装补丁及对应漏洞情况
systeminfo > a.txt & (for %i in (KB2360937 KB2478960 KB2507938 KB2566454 KB2646524 KB2645640 KB2641653 KB944653 KB952004 KB971657 KB2620712 KB2393802 kb942831 KB2503665 KB2592799) do @type a.txt | @find /i "%i" || @echo %i Not Installed!) & del /f /q /a a.txt
从b4dboy的网站中收集而来的tasktool功能的vbs脚本
'''''''''''''''''''''''''''''''''''' ' tasktool.vbs@b4dboy '''''''''''''''''''''''''''''''''''' On Error Resume Next Dim obj, pross, pid, killName pid = WScript.Arguments(1) killName = WScript.Arguments(0) Set obj = GetObject("Winmgmts:{impersonationLevel=impersonate}!\.rootcimv2") Set pross = obj.Execquery("Select * From Win32_Process") Wscript.echo "[PID]" & VbTab & "[ProName]" For Each proccess In pross If (WScript.Arguments.Count = 2) And (CStr(pid) = CStr(proccess.ProcessID)) Then proccess.Terminate 0 ElseIf Ucase(proccess.Name) = Ucase(killName) Then proccess.Terminate 0 Else WScript.echo proccess.ProcessID & VbTab & proccess.Name End If Next
新建用户的vbs脚本
struser=wscript.arguments(0) strpass=wscript.arguments(1) Set lp=createObject("WSCRIPT.NETWORK") oz="WinNT://"&lp.ComputerName Set ob=GetObject(oz) Set oe=GetObject(oz&"/Administrators,group") Set od=ob.create("user",struser) od.SetPassword strpass od.SetInfo Set of=GetObject(oz&"/" & struser & ",user") oe.Add(of.ADsPath) For Each admin in oe.Members if struser=admin.Name then wscript.echo struser & " 建立成功!" wscript.quit end if Next wscript.echo struser & " 用户建立失败!"
《 “一些有用的批处理脚本” 》 有 7 条评论
【技术分享】手把手教你使用PowerShell内置的端口扫描器
http://bobao.360.cn/learning/detail/3961.html
https://pen-testing.sans.org/blog/2017/03/08/pen-test-poster-white-board-powershell-built-in-port-scanner
http://www.blackhillsinfosec.com/?p=4811
Is there any sed like utility for cmd.exe? [closed]
https://stackoverflow.com/questions/127318/is-there-any-sed-like-utility-for-cmd-exe
`
Leave cmd.exe behind and use PowerShell instead.
远离 cmd.exe 和 batch批处理,实用PowerShell替代。
`
Equivalent ‘grep’ and ‘sed’ commands on Windows
https://superuser.com/questions/1522245/equivalent-grep-and-sed-commands-on-windows
`
Or spend the needed time to learn PowerShell, by leveraging all the free resources and videos on Youtube to understand all the parts of PowerShell, and what can be done natively and when you need to code it yourself and when you need to pull in 3rdP tools.
简而言之,Windows不像Linux上有很多很方便的原生文本处理工具支持,如果你对Windows不熟的话更是如此,但如果你的日常工作主要在Windows平台上进行,建议花时间去学习一下PowerShell,它是一门功能丰富的脚本语言,熟悉了之后对于你在Windows系统上的操作管理会很有帮助,而且在近年来的Windows系统中都默认安装了,也不用担心环境问题(版本区别可能有点影响),看你自己的权衡。
`
batch for循环的delims参数支持指定一个字符串作为分隔符吗?而不仅仅只是一个字符——答案是NO,不支持。
“delims=#+#” – more then 1 character as delimiter
https://stackoverflow.com/questions/32690206/delims-more-then-1-character-as-delimiter
https://ss64.com/nt/for_f.html
batch脚本中字符串的拼接
@echo off
SET a = Hello
SET b = World
SET c=%a% and %b%
echo %c%
Hello and World
How to concatenate strings in windows batch file for loop?
https://stackoverflow.com/questions/17743757/how-to-concatenate-strings-in-windows-batch-file-for-loop
batch脚本中字符串子串的截取
https://stackoverflow.com/questions/636381/what-is-the-best-way-to-do-a-substring-in-a-batch-file
https://superuser.com/questions/228794/how-to-extract-part-of-a-string-in-windows-batch-file
https://ss64.com/nt/syntax-substring.html
https://ss64.com/nt/syntax-replace.html
下面的链接是近期在学习和处理Windows batch批处理脚本时的一些还不错的资源,简单来说就是任务驱动,核心知识点了解到了就行,其它的按需搜索就能解决,但总的来说还是不太建议多花时间——batch批处理已经不是流行的内容了,会一些就挺好,复杂的就用PowerShell或是Python等高级编程语言来实现就好,不要纠结。
How-to: Windows Environment Variables
https://ss64.com/nt/syntax-variables.html
How-to: Pass Command Line arguments (Parameters) to a Windows batch file.
https://ss64.com/nt/syntax-args.html
https://ss64.com/nt/for.html
https://ss64.com/nt/delayedexpansion.html
https://ss64.com/nt/for_f.html
https://ss64.com/nt/if.html
https://ss64.com/nt/findstr.html
How does the Windows Command Interpreter (CMD.EXE) parse scripts?
https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts
Creating a batch file to get information on a pc
https://social.technet.microsoft.com/Forums/ie/en-US/58fdb9fd-eb9d-4f0b-bba3-2170f01a6953/creating-a-batch-file-to-get-information-on-a-pc?forum=ITCG
【Batch批处理】for循环全参数详解和实例演示
https://blog.csdn.net/Victor2code/article/details/103555832
Windows bat脚本——for循环用法详解
https://www.cnblogs.com/sll120/p/14827098.html
windows bat脚本(批处理)——for循环,if判断,goto跳转,遍历文件名,start打开网页;
https://www.cnblogs.com/canglongdao/p/12509687.html
How to Copy Folders and Subfolders Using Xcopy Command
https://www.ubackup.com/backup-restore/xcopy-command-to-copy-folders-and-subfolders-6688.html
Windows下如何通过命令行获取Windows操作系统的版本信息?
简单来说wmic os get能获取到好多,其它的就可以按需查注册表来获取。
How to get the ACTUAL version number for Windows 10 from command line? (NOT build number!)
https://superuser.com/questions/1519110/how-to-get-the-actual-version-number-for-windows-10-from-command-line-not-buil
`
>Reg Query “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion” | findstr ReleaseId
>powershell -Command “(Get-ItemProperty -Path ‘HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion’).ReleaseId”
>powershell -Command “Get-ComputerInfo -Property WindowsVersion”
>winver
>wmic os get /?
>wmic os get version /value
Version=10.0.19041
>wmic os get buildnumber /value
BuildNumber=19041
`