2016-12-12 95 views
0

您好我試圖發送命令「關機」到已打開的命令提示符稱爲管理員:交易服務器使用BAT文件,但是當我運行BAT文件什麼也沒有發生。使用批處理文件將命令發送到CMD.exe

我跟着這個問題 - How to execute a command in already open CMD window using VBScirpt

有誰知道爲什麼嗎?

這裏是我的代碼:

:: s 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:115 /lparam:1 
:: h 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:104 /lparam:1 
:: u 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:117 /lparam:1 
:: t 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:116 /lparam:1 
:: d 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:100 /lparam:1 
:: o 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:111 /lparam:1 
:: w 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:119 /lparam:1 
:: n 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:110 /lparam:1 
:: ENTER 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:13 /lparam:1 

:: ENTER 
SendMessage-1.1.2.exe /windowtitle:"Test Server" /message:WM_CHAR /wparam:13 /lparam:1 

:: wait for some time (~3 sec) till the program shuts down, if necessary 
PING -n 4 localhost 1>NUL 

pause 
... 
+0

我並不想在這裏是一個痛苦。只是有問題,他們應該只是這個問題。對你有用的東西可能與其他人稍有不同,所以他們可以添加答案。在這種情況下,只有一個答案,但並非總是如此。請不要在問題中添加「答案」文本。它有助於避免混淆。謝謝 – Bugs

回答

1

我不知道哪個SendMessage函數所使用。我從Dostips.com筆者下載了這個
SendMessage.exe: Access to advanced Windows features:aacini

而與此批我設法在題爲Test-Msg另一個cmd窗口運行關機:

@ECHO OFF 

Set /A WM_CHAR=0x0102 
Set Msg=%WM_CHAR% 

Set Win="Test-Msg" 
::   s h u t d o w n ret 
For %%A in (115 104 117 116 100 111 119 110 13) Do (
echo SendMessage.exe %Win% %Msg% %%A 1 
    SendMessage.exe %Win% %Msg% %%A 1 
) 
Pause 
SendMessage.exe %Win% %Msg% 13 1 
+0

感謝您的解決方案。如果我想在CMD中顯示消息「按任意鍵繼續」之後再輸入另一個回車,我該怎麼做? @LotPings – user1798578

+1

查看上面更改的批次。 – LotPings

+0

通過上面的代碼,Test-Msg cmd窗口保持打開狀態C:/ Desktop有沒有辦法關閉Test-Msg窗口? @LotPings – user1798578