然后该CMD窗口可以关闭,我已经编写了.bat文件以执行备份。
除了非常简单的情况外,我从未编写过VBScripts,如果我的问题不够清楚,我很抱歉。
思路如下 - 使用VBScript输入shutdown {Enter}和yes {Enter},然后关闭该CMD窗口,然后执行备份批处理文件,该文件已设置为在完成备份后启动CMD程序。
操作系统 - Windows XP Professional
谢谢!
PostMessage
和/或SendMessage
。如果有人发布了一个解释如何使用它们的答案,那就太好了。同时,我可以向您展示如何在批处理文件中使用一个名为SendMessage的实用程序来使用此方法。基本上,该实用程序允许您像这样向任意窗口发送任意Windows消息:SendMessage.exe <i>target_specification</i> /message:<i>value</i> /wparam:<i>value</i> /lparam:<i>value</i>
稍后我会讲解target_specification
位,其他参数包括:
/message:value
– the message being sent, specified by code
. In you case it would be either of these:
/message:WM_CHAR
/message:258
/message:0x0102
which all specify the WM_CHAR message.
/wparam:value
– for the WM_CHAR message, this one should be the code of the keystroke being sent.
In your case, since your commands consist of ASCII characters only, all the codes would match the ASCII codes of the corresponding characters. Therefore, you can use an ASCII chart to convert the characters in your commands. The s
, for instance would be
/wparam:115
and h
/wparam:104
and so on.
Note that you will also need to be sending the Enter key presses too. According to the ASCII control code chart, it would be
/wparam:13
/lparam:value
– you can see from the WM_CHAR's manual page that the LPARAM parameter is actually supposed to carry multiple pieces of information as a single numeric value. However, for your specific case it would be enough to just memorise that this parameter should be specified simply as
/lparam:1
/processname:<i>name_of_your_executable</i>
/windowtitle:<i>window_title</i>
title
命令(在调用程序之前设置它)来使标题唯一化。@ECHO OFF
:: s
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:115 /lparam:1
:: h
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:104 /lparam:1
:: u
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:117 /lparam:1
:: t
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:116 /lparam:1
:: d
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:100 /lparam:1
:: o
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:111 /lparam:1
:: w
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:119 /lparam:1
:: n
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:110 /lparam:1
:: ENTER
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:13 /lparam:1
:: y
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:121 /lparam:1
:: e
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:101 /lparam:1
:: s
SendMessage.exe /windowtitle:"My Title" /message:WM_CHAR /wparam:115 /lparam:1
:: ENTER
SendMessage.exe /windowtitle:"My Title" /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
:: proceed with the back-up
...
cmd.exe
会话上使用 SendMessage
(即我只是运行了 cmd.exe
,设置了标题,然后发送了 WM_CHARs),以及在一个带有 ftp.exe
的 CMD 会话中使用 SendMessage
(即从 cmd.exe
中打开 ftp.exe
,它在同一窗口内启动了自己的会话,然后我发送了 WM_CHARs)。两个测试都成功了。我不知道,也许你正在使用一个 DOS (实际 DOS) 程序,它无法接收任何 WM_CHARs。恐怕我无法在我的 Win 7 上验证这一点。 - Andriy M