NirCmd使用说明、使用和符录(全面)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
NirCmd 命令集
NirSoft的每款小工具都可谓经典之作,官网上公布出的90%以上的工具本人都用过或正在用。
着实佩服nirsoft编程人员的功底,每款软件区区几十KB的大小,但它的某些功能确是无法比拟的,废话不多说,有兴趣的可以经常上去猫两眼. /
以下介绍的是一款命令行工具---Nircmd(专用于执行批处理脚本,附带的Nircmdc.exe用于执行控制台命令)。
用好了它,可以提高系统设置的便利性、从而大大增强我们批处理脚本的功能,可能获得某些意想不到的效果。
使用Nircmd另一好处就是提高代码的可移植性,当我们需要提高延时的准确性、操作剪切板等,我们可以使用choice、clip等命令,但xp 下没有choice,clip等命令。
2003,下vista才有,这样为了增加通用性,我们可以舍弃某些被微软抛弃或新提供的命令,而仅附上一nircmd.exe文件,众多命令都被封装在一起,可保证批处理脚本的正常执行及兼容性,何乐而不为?
记录一下本人常用的一些命令,描述错误或不当之处还请各位朋友指出:
以下操作在Vista SP2批处理脚本环境下调试全部通过,某些命令如Speak Text不能保证其他系统下也能正常工作.
1、发声
仅响一声
stdbeep
主板峰鸣器发声
beep [频率] [持续时间]
e: nircmd beep 100 2000
2、等待一段时间(可以精确延时,可以不用再Ping了)
wait [时间]
e: start nircmd wait 3000 && nircmd speak text "等待了3秒钟"
cmdwait [时间] [nircmd命令]
e:nircmd cmdwait 2000 monitor off
3、剪切板操作
clipboard [action] [参数]
action包括参数(set readfile clear writefile addfile saveimage copyimage saveclp loadclp)
e:
nircmd clipboard clear //清空剪切板
nircmd clipboard set "这是剪切板上的内容"
nircmd clipboard readfile "c:\a.txt"
4、发送按键sendkey (类似vbs的sendkeys,更多用法请自己去发掘) sendkey [key] [press|down|up]
e:以下命令在批处理中运行,发送ctrl+v将内容粘贴进记事本
start notepad&&nircmd cmdwait 2000 clipboard set "晚安
"&&nircmd sendkey ctrl down
nircmd sendkey v press
nircmd sendkey ctrl up //这一句不可少,释放按键
弊端:操作较繁琐,对长字符串尽量先放进剪切板,再ctrl+v
别外对于特殊按键,可以用虚拟键码表示,具体可以查看相关资料. 如0x8表示BackSpace键,0x6E表示 . 键等
5、朗读文本
speak [类型] [文本或文件名] [速度] [音量]
类型(text xml file)
速度(-10到10)
音量(0到100)
e:nircmd speak file "c:\a.txt" 2 80
6、弹出信息框
infobox [内容] [标题]
e:nircmd infobox "确定退出" "请注意"
Qbox [内容] [标题] [运行的程序] //如果回答"是"则运行后面的程序
e:nircmd qbox "打开画图软件吗?" "请回答" "mspaint"
QboxTop 与qbox相似,只是信息框顶端显示
Qboxcom
Qboxcom [内容] [标题] [NirCmd命令] 回答"是",则运行后面命令e:nircmd Qboxcom "Do you Love me ?" "??" speak text "Me too."
Qboxcomtop与Qboxcom相似,顶端显示
7、等待进程结束
waitprocess [进程名] [命令]
e: nircmd waitprocess regedit.exe infobox "注册表编辑器已关闭了" "注意"
8、关闭进程
closeprocess [进程名]
e: nircmd closeprocess cmd.exe
killprocess [name]
e:N/A
9、操作服务
service [动作] [服务名]
动作包括{start stop pause continue restart auto manual disabled}
e: nircmd service stop "VMware NAT Service"
e: nircmd service manual "VMware NAT Service"
10、转换图片格式 (支持.bmp, .gif, .png, .jpg, .tiff)
e:nircmd convertimages "c:\a.gif" .jpg
11、截屏(支持图片格式.bmp, .gif, .png, .jpg)
全屏:
savescreenshot [文件名]
e:nircmd savescreenshot "c:\a.jpg"
活动窗口
savescreenshotwin [文件名]
e:N/A
12、复制文件
shellcopy [源路径] [目标路径] {参数}
参数{yestoall noerrorui silent nosecattr}很容易理解,不解释了e:nircmd shellcopy "d:\a.iso" "c:\" yestoall
13、删除文件
filldelete [文件名]
e:nircmd filldelete "c:\a.txt"
14、关闭显示屏
monitor [action]
action包括(off on low)
e:nircmd monitor off
15、设置分辨率
setdisplay [宽] [高] [颜色位]
e:nircmd setdisplay 1024 768 24
16、操作注册表
regedit [键] [键值] 用于打开注册表,并跳转至指定的键
regsetval [类型] [key] [value name] [value] 添加注册表项
其中的类型分为:sz(字符串)、expand_sz(扩展字符串)、dword(32位双字节型)、binarys(二进制)
regdelkey [key] 删除键(如果存在子键,会导致删除失败)
regdelval [key] [value] 删除键值
①、跳转至run键
regedit
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion \Run"
②、删除run中的值aa
regdelval
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion \Run" "aa"
③、run中添加字符串键值aa,字符串内容为bb
nircmd regsetval sz
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "aa" "bb"
它的功能还远不止这些,感兴趣的朋友可以自己去发觉
其他本人不常用或没用过却很强大的命令,操作方法可以去看附带的帮助文件:
17、操作ini文件
18、连接网络
19、运行三方程序或命令
exec [show/hide] [application + command-line]
exec2 [show/hide] [working folder] [application + command-line]
execmd [command]
shexec [operation] [filename]
20、windows窗体操作
win [action] [find] [window to find] [Additional Parameters] win child [find] [top window to find] [action] [find] [child window to find] [Additional Parameters]
21、鼠标操作
sendmouse [right | left | middle] [down | up | click | dblclick]
sendmouse [move] [x] [y]
sendmouse [wheel] [Wheel Value]
22、系统音量调节与设置
changesysvolume [volume change] {Component} {Device Index} changesysvolume2 [left volume change] [right volume change] {Component} {Device Index}
setvolume [device] [left-volume] [right-volume] setsysvolume [volume] {Component} {Device Index}
23、修改文件或文件夹时间
setfiletime [filename or wildcard] [Created Date] {Modified Date} {Accessed Date}
setfilefoldertime [filename, folder or wildcard] [Created Date] {Modified Date} {Accessed Date}
24、清空回收站
emptybin {drive}
e:emptybin f:
25、关闭、重启注销等操作
exitwin [shutdown type] {additional option}
.
.
.
Nircmd官方链接: /utils/nircmd.html
②“sendkey 0x25 press”是sendkey命令的应用,0x25是左键对应的虚拟键码,0x26、0x27和0x28分别是上、右和下。
附虚拟键码表:
/manual/low_level_vk_list.html
注:对于命令中的[Key],a-z、0-9、F1-F12、ctrl、shift、alt、esc等都直接写即可,像上下左右、回车、Delete之类的特殊按键才需要使用虚拟键码。
// Virtual Keys, Standard Set
#define VK_LBUTTON 0x01
#define VK_RBUTTON 0x02
#define VK_CANCEL 0x03
#define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */
#define VK_BACK 0x08
#define VK_TAB 0x09
#define VK_CLEAR 0x0C
#define VK_RETURN 0x0D
#define VK_SHIFT 0x10
#define VK_CONTROL 0x11
#define VK_MENU 0x12
#define VK_PAUSE 0x13
#define VK_CAPITAL 0x14
#define VK_KANA 0x15
#define VK_HANGEUL 0x15 /* old name - should be here for compatibility */
#define VK_HANGUL 0x15
#define VK_JUNJA 0x17
#define VK_FINAL 0x18
#define VK_HANJA 0x19
#define VK_KANJI 0x19
#define VK_ESCAPE 0x1B
#define VK_CONVERT 0x1C
#define VK_NONCONVERT 0x1D
#define VK_ACCEPT 0x1E
#define VK_MODECHANGE 0x1F
#define VK_SPACE 0x20
#define VK_PRIOR 0x21
#define VK_NEXT 0x22
#define VK_END 0x23
#define VK_HOME 0x24
#define VK_LEFT 0x25
#define VK_UP 0x26
#define VK_RIGHT 0x27
#define VK_DOWN 0x28
#define VK_Select 0x29
#define VK_PRINT 0x2A
#define VK_EXECUTE 0x2B
#define VK_SNAPSHOT 0x2C
#define VK_Insert 0x2D
#define VK_Delete 0x2E
#define VK_HELP 0x2F
/* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ #define VK_LWIN 0x5B
#define VK_RWIN 0x5C
#define VK_APPS 0x5D
#define VK_NUMPAD0 0x60
#define VK_NUMPAD1 0x61
#define VK_NUMPAD2 0x62
#define VK_NUMPAD3 0x63
#define VK_NUMPAD4 0x64
#define VK_NUMPAD5 0x65
#define VK_NUMPAD6 0x66
#define VK_NUMPAD7 0x67
#define VK_NUMPAD8 0x68
#define VK_NUMPAD9 0x69
#define VK_MULTIPLY 0x6A
#define VK_ADD 0x6B
#define VK_SEPARATOR 0x6C
#define VK_SUBTRACT 0x6D
#define VK_DECIMAL 0x6E
#define VK_DIVIDE 0x6F
#define VK_F1 0x70
#define VK_F2 0x71
#define VK_F3 0x72
#define VK_F4 0x73
#define VK_F5 0x74
#define VK_F6 0x75
#define VK_F7 0x76
#define VK_F8 0x77
#define VK_F9 0x78
#define VK_F10 0x79
#define VK_F11 0x7A
#define VK_F12 0x7B
#define VK_F13 0x7C
#define VK_F14 0x7D
#define VK_F15 0x7E
#define VK_F16 0x7F
#define VK_F17 0x80
#define VK_F18 0x81
#define VK_F19 0x82
#define VK_F20 0x83
#define VK_F21 0x84
#define VK_F22 0x85
#define VK_F23 0x86
#define VK_F24 0x87
#define VK_NUMLOCK 0x90 #define VK_SCROLL 0x91。