Windows API の力を借りる
かなりベタな方法で、まだまだ実用段階ではありませんが、一応成功したので。
まず、既に存在するファイルを上書き保存するキー操作を想定しています。
スカイプのログインは済んでいるという前提で、スクリプトは cscript.exe で実行し、
実行後メッセージボックスが表示されたら、スカイプに手動でフォーカスを移しておきます
Set WshShell = WScript.CreateObject( "WScript.Shell" )
Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")
oSkype.Attach
MsgBox("OK")
Public Sub Skype_FileTransferStatusChanged(ByRef aTransfer, ByVal aStatus)
WScript.Echo ">File Transfer " & aTransfer.Id & " status " & FTStatusToText(aStatus)
' 転送受信要求
if FTStatusToText(aStatus) = "New" then
' ファイル受信ウインドウをアクティブにする
Call WshShell.Run( "API_CALLBACK.exe", 0, True )
WScript.Sleep(10000)
' 受け付ける
WshShell.SendKeys("{ENTER}")
WScript.Sleep(3000)
' 名前を付けて保存
WshShell.SendKeys("%S")
WScript.Sleep(3000)
' 上書き確認
WshShell.SendKeys("%Y")
end if
' 転送終了のイベント
if FTStatusToText(aStatus) = "Completed" then
WScript.Sleep(3000)
' ウインドウを閉じる
WshShell.SendKeys("%{F4}")
end if
End Sub
Function FTStatusToText(aStatus)
Const fileTransferStatusNew = 0
Const fileTransferStatusConnecting = 1
Const fileTransferStatusWaitingForAccept = 2
Const fileTransferStatusTransferring = 3
Const fileTransferStatusTransferringOverRelay = 4
Const fileTransferStatusPaused = 5
Const fileTransferStatusRemotelyPaused = 6
Const fileTransferStatusCancelled = 7
Const fileTransferStatusCompleted = 8
Const fileTransferStatusFailed = 9
Select Case aStatus
Case fileTransferStatusNew
FTStatusToText = "New"
Case fileTransferStatusConnecting
FTStatusToText = "Connecting"
Case fileTransferStatusWaitingForAccept
FTStatusToText = "Waiting for Accept"
Case fileTransferStatusTransferring
FTStatusToText = "Transferring"
Case fileTransferStatusTransferringOverRelay
FTStatusToText = "Transferring over Relay"
Case fileTransferStatusPaused
FTStatusToText = "Paused"
Case fileTransferStatusRemotelyPaused
FTStatusToText = "Remotely Paused"
Case fileTransferStatusCancelled
FTStatusToText = "Cancelled"
Case fileTransferStatusCompleted
FTStatusToText = "Completed"
Case fileTransferStatusFailed
FTStatusToText = "Failed"
End Select
End Function
ここで、API_CALLBACK.exe は、以下の VB.NET で作成したものです。
フォームは使わずに、目的の処理が済むと即終了します
要するに、ApplicationEvents.vb を使っています。
実装方法は こちらを参照して下さい
Imports System.Runtime.InteropServices
Imports System.Text
Namespace My
Partial Friend Class MyApplication
' ******************************************************
' Callback 関数の定義( 通常 )
' ******************************************************
Public Delegate Function EnumWindowsCallbackNormal( _
ByVal hWnd As Integer, _
ByVal lParam As Integer) As Boolean
' ******************************************************
' Callback 呼び出し 関数の定義
' ******************************************************
_
Public Shared Function EnumWindows( _
ByVal callback As EnumWindowsCallbackNormal, _
ByVal lParam As Integer) As Integer
End Function
' ******************************************************
' 情報取得用 API
' ******************************************************
_
Public Shared Function ShowWindow(ByVal hWnd As Integer, _
ByVal nCmdShow As Integer _
) As Integer
End Function
_
Public Shared Function GetWindowText(ByVal hWnd As Integer, _
ByVal lpString As StringBuilder, _
ByVal nMaxCount As Integer) As Integer
End Function
_
Public Shared Function GetClassName(ByVal hwnd As Integer, _
ByVal lpClassName As StringBuilder, _
ByVal cch As Integer) As Integer
End Function
Const STRING_BUFFER_LENGTH As Integer = 255
' ******************************************************
' 開始( 処理後終了 )
' ******************************************************
Private Sub MyApplication_Startup(ByVal sender As Object, _
ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
' Callback 関数のアドレスの渡し方
Dim func As EnumWindowsCallbackNormal = _
AddressOf ActiveProcessListNormal
EnumWindows( _
CType( _
AddressOf ActiveProcessListNormal, _
EnumWindowsCallbackNormal _
), 0)
e.Cancel = True
End Sub
' ******************************************************
' Callback 関数( 通常 )
' ******************************************************
Private Function ActiveProcessListNormal(ByVal hWnd As Integer, _
ByVal lParam As Integer) As Boolean
Dim windowText As New StringBuilder(STRING_BUFFER_LENGTH)
Dim className As New StringBuilder(STRING_BUFFER_LENGTH)
GetWindowText(hWnd, windowText, STRING_BUFFER_LENGTH)
GetClassName(hWnd, className, STRING_BUFFER_LENGTH)
Dim target As String = windowText.ToString() + ""
If target.Length >= 5 Then
If target.Substring(0, 5) = "Skype" Then
If target.IndexOf("ファイルを受信しています") >= 0 Then
Console.WriteLine( _
String.Format("{0}|{1}|{2}", _
windowText.ToString(), _
className.ToString(), _
hWnd.ToString()) _
)
ShowWindow(hWnd, 9)
End If
End If
End If
Return True
End Function
End Class
End Namespace
|
|