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"