2015-09-17 40 views
-2

是否可以使用批處理腳本訪問應用程序的菜單欄?我需要能夠編寫一些在打開應用程序後可以選擇文件>另存爲。使用批處理腳本訪問菜單欄。

+1

批處理文件本身不能與圖形用戶界面交互。你想與哪些應用程序進行交互? – SomethingDark

+0

也許您可能感興趣的AutoHotKey(在網上查找)... – aschipfl

+0

或者's SendKeys'函數的vbscript,如果你在工作,並且不能安裝第三方軟件(但肯定嘗試使用AutoHotKey如果可以的話; SendKeys是臭名昭着的不可靠的)。 – SomethingDark

回答

0

腳本示例在記事本中打開文件並將按鍵發送到: 1.編寫一些文本。 2.保存文件。 3.關閉記事本應用程序。 (連續3次)

/!\請注意,該批處理腳本將擊鍵發送到您的焦點./應用!\

@if (@CodeSection == @Batch) @then 
@echo off 
set "pr=_somefile.txt" 
if NOT exist %pr% COPY NUL %pr% 

rem Use %SendKeys% to send keys to the keyboard buffer 
set SendKeys=CScript //nologo //E:JScript "%~F0" 

for /L %%i in (1,1,3) do ( 
    rem Start notepad 
    start "" notepad %pr% 
    %SendKeys% "^{END}{ENTER}Hello, world! {(} started 1 line after the end of file {)}{ENTER}" 
    %SendKeys% "Typing on notepad few lines{ENTER}" 
    %SendKeys% "Saving the file{ENTER}^s" 
    %SendKeys% "closing notepad in 1 sec !{ENTER}{ENTER}...............................{ENTER}" 
    @timeout /T 1 /nobreak >NUL 
    %SendKeys% "^s" 
    %SendKeys% "^s%%{F4}" 
    @timeout /T 1 /nobreak >NUL 
) 
goto :EOF 

@end 
// JScript section 
var WshShell = WScript.CreateObject("WScript.Shell"); 
WshShell.SendKeys(WScript.Arguments(0)); 

一些參考閱讀。
https://msdn.microsoft.com/en-us/library/aa266279(v=vs.60).aspx
http://social.technet.microsoft.com/wiki/contents/articles/5169.vbscript-sendkeys-method.aspx
http://ss64.com/vb/sendkeys.html

信用:https://stackoverflow.com/a/17050135