Skype4COM ファイル転送自動受信

Windows API の力を借りる
かなりベタな方法で、まだまだ実用段階ではありませんが、一応成功したので。

まず、既に存在するファイルを上書き保存するキー操作を想定しています。
スカイプのログインは済んでいるという前提で、スクリプトは cscript.exe で実行し、
実行後メッセージボックスが表示されたら、スカイプに手動でフォーカスを移しておきます
ここで、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