CLOSE  
On Error Resume Next

Set oWshShell = WScript.CreateObject("WScript.Shell")

oWshShell.Run("%SystemRoot%\system32\eventvwr.msc /s")
WScript.Sleep(3000)
oWshShell.AppActivate("Event Viewer")
oWshShell.SendKeys("{PGUP}")     'Hit Page Up key to put focus at top of tree.
oWshShell.SendKeys("{DOWN}")     'Hit the down-arrow key three times.
oWshShell.SendKeys("{DOWN}")
oWshShell.SendKeys("{DOWN}")
oWshShell.SendKeys("%A")         'Hit Alt-A for the Action menu.
WScript.Sleep(500)
oWshShell.SendKeys("{DOWN}")
oWshShell.SendKeys("{ENTER}")    'Hit Enter key.
WScript.Sleep(1000)
oWshShell.SendKeys("c:\EventLog.evt")
oWshShell.SendKeys("{TAB}")      'Tab over to the Save button.
oWshShell.SendKeys("{TAB}")
oWshShell.SendKeys("{ENTER}")
WScript.Sleep(600)
oWshShell.SendKeys("{LEFT}")     'Enter Yes, if necessary, to overwrite previously existing file.
oWshShell.SendKeys("{ENTER}")
oWshShell.SendKeys("%{F4}")      'Alt-F4 closes the MMC window.

図6●GUIベースのアプリケーションを実行する「keystrokes.vbs」
コマンド・インターフェースのないGUIベースのアプリケーションに対し,キーボードからの入力をエミュレーションして操作する。この例では,イベント・ビューアを起動してシステム・ログをCドライブに保存する操作を実行している。

Copyright (C) 2004 Nikkei Business Publications, Inc. All rights reserved.