使用批处理文件向 CMD.exe 发送命令
Send Command to CMD.exe using Batch file
您好,我正在尝试将命令 "shutdown" 发送到一个已经打开的命令提示符 Administrator: Transaction Server 使用 BAT 文件,但是当我 运行 BAT 文件没有任何反应。
我关注了这个问题 - 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
...
我不知道你用的是哪个sendmessage。我下载了这个
SendMessage.exe: Access to advanced Windows features 来自 Dostips.com author:aacini
通过这批,我设法 运行 在另一个名为 Test-Msg
的命令 window 中关闭:
@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
您好,我正在尝试将命令 "shutdown" 发送到一个已经打开的命令提示符 Administrator: Transaction Server 使用 BAT 文件,但是当我 运行 BAT 文件没有任何反应。
我关注了这个问题 - 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
...
我不知道你用的是哪个sendmessage。我下载了这个
SendMessage.exe: Access to advanced Windows features 来自 Dostips.com author:aacini
通过这批,我设法 运行 在另一个名为 Test-Msg
的命令 window 中关闭:
@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