bat脚本传递参数
1. 涓や釜宸茶繍琛岀殑镓瑰勭悊涔嬮棿杩涜屼紶阃掓暟鍊
VBS镓嶈 妯℃嫙阌鐩樿緭鍏
Set objShell = CreateObject("Wscript.Shell")
strCommandLine = "ttpsetup.exe" '钖锷ㄥ畨瑁呯▼搴
objShell.Run(strCommandLine)
set WshShell = CreateObject("WScript.Shell")
WScript.Sleep 3000 '寤舵椂3绉
WshShell.SendKeys "s" '妯℃嫙鎸変笅 S 阌寮濮嫔畨瑁
WScript.Sleep 300 '寤舵椂0.3绉
WshShell.SendKeys "a" '妯℃嫙鎸変笅 A 阌钖屾剰鍗忚
WScript.Sleep 300
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 300
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 300
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 2000
WshShell.SendKeys "" '妯℃嫙鎸変笅 Tab 阌阃夋嫨瀹夎呴”鐩
WScript.Sleep 300
WshShell.SendKeys ""
WScript.Sleep 300
WshShell.SendKeys " " '妯℃嫙鎸変笅绌烘牸阌铡婚櫎瀹夎呯栌搴﹁秴绾ф悳闇镐竴琛屽墠镄勨垰鍙
WScript.Sleep 300
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌瀹屾垚链钖庝竴姝
鎶娄互涓娄唬镰佸嶅埗鍒拌颁簨链涓锛埚彸杈圭殑鏂囧瓧鏄璇存槑锛屼竴璧峰嶅埗涔熶笉褰卞搷锛夛纴鍐嶅彟瀛树负 AutoSetup.vbs 锛屾妸姝ゆ枃浠跺瓨鏀惧湪鍗冨崈闱椤惉瀹夎呮墽琛岀▼搴忥纸ttpsetup.exe锛夊悓涓鐩褰曚笅锛屽弻鍑 AutoSetup.vbs 鍗冲彲镊锷ㄥ畬鎴愬崈鍗冮润钖镄勫畨瑁呫傛垚锷熺殑鍏抽敭鏄锛屼綘蹇呴’鍏埚畨瑁呬竴娆″崈鍗冮润钖锛岀劧钖庤颁綇姣忎竴姝ョ殑鎸夐敭鏄浠涔堬纴杩欎釜鏂囦欢灏卞彲浠ユ嬁铡诲埆镄勬満涓婃墽琛屼简銆
SendKeys 镄勫弬鏁拌存槑锛
浣跨敤 SendKeys 鏂规硶鍙浠ュ皢阌鍑诲彂阃佸埌镞犺嚜锷ㄥ寲鐣岄溃镄勫簲鐢ㄧ▼搴忎腑銆傚氭暟阌鐩桦瓧绗﹂兘鍙鐢ㄤ竴涓阌鍑昏〃绀恒傛煇浜涢敭鐩桦瓧绗︾敱澶氢釜阌鍑荤粍钖堣屾垚锛堜緥濡傦纴CTRL+SHIFT+HOME锛夈傝佸彂阃佸崟涓阌鐩桦瓧绗︼纴璇峰皢瀛楃︽湰韬浣滀负 string 鍙傛暟鍙戦併备緥濡傦纴瑕佸彂阃佸瓧姣 x锛屽垯璇峰彂阃 string 鍙傛暟 "x"銆
鍙浣跨敤 SendKeys 钖屾椂鍙戦佸氢釜阌鍑汇备负姝わ纴鍙灏嗘疮涓阌鍑绘寜椤哄簭鎺掑垪鍦ㄤ竴璧凤纴浠ユゆ潵鍒涘缓琛ㄧず涓绯诲垪阌鍑荤殑澶嶅悎瀛楃︿覆鍙傛暟銆备緥濡傦纴瑕佸彂阃侀敭鍑 a銆乥 鍜 c锛屽垯闇瑕佸彂阃佸瓧绗︿覆鍙傛暟 "abc" 銆係endKeys 鏂规硶灏嗘煇浜涘瓧绗︾敤浣滃瓧绗︾殑淇楗扮︼纸钥屼笉浣跨敤鍏舵湰韬镄勫惈涔夛级銆傝繖缁勭壒娈婄殑瀛楃﹀彲鍖呮嫭鍦嗘嫭鍙枫佷腑𨰾鍙枫佸ぇ𨰾鍙凤纴浠ュ强锛
锷犲彿 "+"
鎻掑叆璁板彿 "^"
锏惧垎鍙 "%"
鍜屸滈潪钬濈﹀彿 "~"
鐢ㄥぇ𨰾鍙 ""銆係endKeys涓浣跨敤镄勪腑𨰾鍙 "[ ]" 镞犱换浣旷壒娈婂惈涔夛纴浣嗘槸蹇呴’鎶婂畠浠𨰾鍦ㄥぇ𨰾鍙蜂腑锛屼互渚垮圭撼纭瀹炶佽祴浜埚叾鐗规畩钖涔夌殑搴旂敤绋嫔簭锛堜緥濡傦纴瀵逛簬锷ㄦ佹暟鎹浜ゆ崲 (DDE) 灏辨槸杩欐牱锛夈
瑕佸彂阃佸乏涓𨰾鍙峰瓧绗︼纴璇峰彂阃佸瓧绗︿覆鍙傛暟 ""锛涜佸彂阃佸彸涓𨰾鍙峰瓧绗︼纴璇峰彂阃佸瓧绗︿覆鍙傛暟 ""銆
瑕佸彂阃佸乏澶ф嫭鍙峰瓧绗︼纴璇峰彂阃佸瓧绗︿覆鍙傛暟 ""锛涜佸彂阃佸彸澶ф嫭鍙峰瓧绗︼纴璇峰彂阃佸瓧绗︿覆鍙傛暟 ""銆
镆愪簺阌鍑讳笉鐢熸垚瀛楃︼纸濡 ENTER 鍜 TAB锛夈傛煇浜涢敭鍑昏〃绀烘搷浣滐纸濡 BACKSPACE 鍜 BREAK锛夈傝佸彂阃佽繖浜涚被鍨嬬殑阌鍑伙纴璇峰彂阃佷笅琛ㄤ腑鍒楀嚭镄勫弬鏁帮细
绌烘牸阌 " "
阃镙奸敭 鎴 鎴
BREAK
DELETE 鎴
钖戜笅阌
钖戜笂阌
钖戝乏阌
钖戝彸阌
END
ENTER 鎴 ~
ESC
TAB
CAPS LOCK
HELP
HOME
INSERT 鎴
NUM LOCK
PAGE DOWN
PAGE UP
PRINT SCREEN
SCROLL LOCK
F1
F2
F3
F4
F5
F6
F7
F8
F9
F10
F11
F12
瑕佸彂阃佺敱甯歌勯敭鍑诲拰 SHIFT銆丆TRL 鎴 ALT 缁勫悎钥屾垚镄勯敭鐩桦瓧绗︼纴璇峰垱寤鸿〃绀鸿ラ敭鍑荤粍钖堢殑澶嶅悎瀛楃︿覆鍙傛暟銆傚彲阃氲繃鍦ㄥ父瑙勯敭鍑讳箣鍓嶆坊锷犱竴涓鎴栧氢釜浠ヤ笅鐗规畩瀛楃︽潵瀹屾垚涓婅堪镎崭綔锛
SHIFT +
CTRL ^
ALT %
娉ㄦ剰锛氲繖镙蜂娇鐢ㄦ椂锛屼笉鐢ㄥぇ𨰾鍙锋嫭璧疯繖浜涚壒娈婂瓧绗︺
瑕佹寚瀹氩湪鎸変笅澶氢釜鍏朵粬阌镞讹纴鎸変笅 SHIFT銆丆TRL 鍜 ALT 镄勭粍钖堬纴璇峰垱寤哄嶅悎瀛楃︿覆鍙傛暟锛岀敤𨰾鍙锋嫭璧峰叾涓镄勭粍钖堥敭銆备緥濡傦纴瑕佸彂阃佺殑缁勫悎阌鎸囧畾锛
濡傛灉鍦ㄦ寜 e 鍜 c 镄勫悓镞舵寜 SHIFT 阌锛屽垯鍙戦佸瓧绗︿覆鍙傛暟 "+(ec)"銆
濡傛灉鍦ㄦ寜 e 镞跺彧鎸 c锛堣屼笉鎸 SHIFT锛夛纴鍒椤彂阃佸瓧绗︿覆鍙傛暟 "+ec"銆
鍙浣跨敤 SendKeys 鏂规硶鍙戦佷竴绉嶅湪涓琛屽唴閲嶅嶆寜阌镄勯敭鍑汇备负姝わ纴瑕佸垱寤哄嶅悎瀛楃︿覆鍙傛暟锛屼互鎸囧畾瑕侀吨澶岖殑阌鍑伙纴骞跺湪鍏跺悗鎸囧畾閲嶅嶆℃暟銆傚彲浣跨敤 褰㈠纺镄勫嶅悎瀛楃︿覆鍙傛暟𨱒ュ畬鎴愪笂杩版搷浣溿备緥濡傦纴濡傛灉瑕佸彂阃 10 娆 "x"锛屽垯闇瑕佸彂阃佸瓧绗︿覆鍙傛暟 ""銆傝风‘淇濆湪阌鍑诲拰鏁板瓧涔嬮棿链変竴涓绌烘牸銆
娉ㄦ剰锛氩彧鍙浠ュ彂阃侀吨澶嶆寜涓涓阌镄勯敭鍑汇备緥濡傦纴鍙浠ュ彂阃 10 娆 "x"锛屼絾涓嶅彲鍙戦 10 娆 "Ctrl+x"銆
娉ㄦ剰锛氢笉鑳藉悜搴旂敤绋嫔簭鍙戦 PRINT SCREEN 阌 銆
渚嫔瓙1锛氩叧链鸿剼链 锛堟ā𨰾熸寜阌涓猴细Ctrl + Esc銆乽銆乽 锛
鎶娄互涓嬩唬镰佸嶅埗镊宠颁簨链锛屽彟瀛树负 off.vbs
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^uu"
渚嫔瓙2锛氶吨钖鑴氭湰 锛堟ā𨰾熸寜阌涓猴细Ctrl + Esc銆乽銆乺 锛
鎶娄互涓嬩唬镰佸嶅埗镊宠颁簨链锛屽彟瀛树负 reboot.vbs
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^ur"
渚嫔瓙3锛氩垏鎹㈣緭鍏ユ硶 锛堟ā𨰾熷悓镞舵寜涓嬶细Shift Ctrl 锛
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "+(^)"
渚嫔瓙4锛氲緭鍏 cn-dos.net! 镊宠颁簨链骞朵缭瀛树负 CnDos.txt
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad"
WScript.Sleep 1500
WshShell.AppActivate "镞犳爣棰 - 璁颁簨链"
WshShell.SendKeys "c"
WScript.Sleep 200
WshShell.SendKeys "n"
WScript.Sleep 200
WshShell.SendKeys "-"
WScript.Sleep 200
WshShell.SendKeys "d"
WScript.Sleep 200
WshShell.SendKeys "o"
WScript.Sleep 200
WshShell.SendKeys "s"
WScript.Sleep 200
WshShell.SendKeys "."
WScript.Sleep 200
WshShell.SendKeys "n"
WScript.Sleep 200
WshShell.SendKeys "e"
WScript.Sleep 200
WshShell.SendKeys "t"
WScript.Sleep 200
WshShell.SendKeys "!"
WScript.Sleep 200
WshShell.SendKeys "%FS"
WScript.Sleep 500
WshShell.SendKeys "C"
WScript.Sleep 200
WshShell.SendKeys "n"
WScript.Sleep 200
WshShell.SendKeys "D"
WScript.Sleep 200
WshShell.SendKeys "o"
WScript.Sleep 200
WshShell.SendKeys "s"
WScript.Sleep 200
WshShell.SendKeys "%S"
WScript.Sleep 500
WshShell.SendKeys "%FX"
渚嫔瓙5锛氲嚜锷ㄥ畾镞跺瓨鐩樼殑璁颁簨链锛堟よ剼链𨱒ヨ嚜缃戜笂锛
'绗涓閮ㄥ垎锛氩畾涔夊彉閲忓拰瀵硅薄
Dim WshShell, AutoSaveTime, TXTFileName
AutoSaveTime=(1000*60*1) '镊锷ㄥ瓨鐩樻椂闂翠负1鍒嗛挓
Set WshShell=WScript.CreateObject("WScript.Shell")
TXTFileName=InputBox("缁欐枃链璧峰悕(涓嶈兘鐢ㄤ腑鏂囧拰绾鏁板瓧)锛")
'绗浜岄儴鍒嗭细镓揿紑骞舵縺娲昏颁簨链
WshShell.Run "notepad"
WScript.Sleep 200
WshShell.AppActivate "镞犳爣棰 - 璁颁簨链"
'绗涓夐儴鍒嗭细鐢ㄨ緭鍏ョ殑鏂囦欢钖嶅瓨鐩
WshShell.SendKeys "^s"
WScript.Sleep 300
WshShell.SendKeys TXTFileName
WScript.Sleep 300
WshShell.SendKeys "%s"
WScript.Sleep AutoSaveTime
'绗锲涢儴鍒嗭细镊锷ㄥ畾镞跺瓨鐩
While WshShell.AppActivate (TXTFileName)=True
WshShell.SendKeys "^s"
WScript.Sleep AutoSaveTime
Wend
WScript.Quit
渚嫔瓙锛
set objShell = CreateObject("Wscript.Shell")
strCommandLine = "psetup755281.exe" '钖锷ㄥ畨瑁呯▼搴
objShell.Run(strCommandLine)
set WshShell = CreateObject("WScript.Shell")
WScript.Sleep 2000 '寤舵椂3绉
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 300 '寤舵椂3绉
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 300 '寤舵椂3绉
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 5200 '寤舵椂3绉
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 300 '寤舵椂3绉
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 300 '寤舵椂3绉
WshShell.SendKeys "" '妯℃嫙鎸変笅锲炶溅阌镓ц屼笅涓姝
WScript.Sleep 200
WshShell.SendKeys " " '妯℃嫙鎸変笅绌烘牸阌铡婚櫎瀹夎呯栌搴﹁秴绾ф悳闇镐竴琛屽墠镄勨垰鍙
WScript.Sleep 100
WshShell.SendKeys "" '妯℃嫙鎸変笅 Tab 阌阃夋嫨瀹夎呴”鐩
WScript.Sleep 200
WshShell.SendKeys " " '妯℃嫙鎸変笅绌烘牸阌铡婚櫎瀹夎呯栌搴﹁秴绾ф悳闇镐竴琛屽墠镄勨垰鍙
WScript.Sleep 200 '寤舵椂0.3绉
WshShell.SendKeys "f" '妯℃嫙鎸変笅 F阌钖屾剰鍗忚
2. python怎么执行bat文件并传递参数给bat文件
使用os模块的system方法可以执行命令,例如执行D盘的cmd.bat批处理脚本并传入参数p1:
importos
os.system(r'D:cmd.batp1')
3. 怎样在BAT脚本里面调用exe且提供输入参数
bat文件中是可以直接执行exe的,如果不在当前目录,请加完整路径。
有参数的命令和普通执行exe是一样的,如
batch.exe
-a
c:\windows\system32\netstat.exe
-an
如果路径中有空格,必须用引号引起来,如
"c:\program
files\aa\aa.exe
-b"