Windows API の力を借りる![]() かなりベタな方法で、まだまだ実用段階ではありませんが、一応成功したので。 まず、既に存在するファイルを上書き保存するキー操作を想定しています。 スカイプのログインは済んでいるという前提で、スクリプトは cscript.exe で実行し、 実行後メッセージボックスが表示されたら、スカイプに手動でフォーカスを移しておきます 01. Set WshShell = WScript.CreateObject( "WScript.Shell" ) 02. Set oSkype = WScript.CreateObject( "Skype4COM.Skype" , "Skype_" ) 03. 04. oSkype.Attach 05. 06. MsgBox( "OK" ) 07. 08. Public Sub Skype_FileTransferStatusChanged( ByRef aTransfer, ByVal aStatus) 09. WScript.Echo ">File Transfer " & aTransfer.Id & " status " & FTStatusToText(aStatus) 10. 11. ' 転送受信要求 12. if FTStatusToText(aStatus) = "New" then 13. ' ファイル受信ウインドウをアクティブにする 14. Call WshShell.Run( "API_CALLBACK.exe" , 0, True ) 15. WScript.Sleep(10000) 16. ' 受け付ける 17. WshShell.SendKeys( "{ENTER}" ) 18. WScript.Sleep(3000) 19. ' 名前を付けて保存 20. WshShell.SendKeys( "%S" ) 21. WScript.Sleep(3000) 22. ' 上書き確認 23. WshShell.SendKeys( "%Y" ) 24. end if 25. 26. ' 転送終了のイベント 27. if FTStatusToText(aStatus) = "Completed" then 28. WScript.Sleep(3000) 29. ' ウインドウを閉じる 30. WshShell.SendKeys( "%{F4}" ) 31. end if 32. 33. End Sub 34. 35. Function FTStatusToText(aStatus) 36. 37. Const fileTransferStatusNew = 0 38. Const fileTransferStatusConnecting = 1 39. Const fileTransferStatusWaitingForAccept = 2 40. Const fileTransferStatusTransferring = 3 41. Const fileTransferStatusTransferringOverRelay = 4 42. Const fileTransferStatusPaused = 5 43. Const fileTransferStatusRemotelyPaused = 6 44. Const fileTransferStatusCancelled = 7 45. Const fileTransferStatusCompleted = 8 46. Const fileTransferStatusFailed = 9 47. 48. Select Case aStatus 49. Case fileTransferStatusNew 50. FTStatusToText = "New" 51. Case fileTransferStatusConnecting 52. FTStatusToText = "Connecting" 53. Case fileTransferStatusWaitingForAccept 54. FTStatusToText = "Waiting for Accept" 55. Case fileTransferStatusTransferring 56. FTStatusToText = "Transferring" 57. Case fileTransferStatusTransferringOverRelay 58. FTStatusToText = "Transferring over Relay" 59. Case fileTransferStatusPaused 60. FTStatusToText = "Paused" 61. Case fileTransferStatusRemotelyPaused 62. FTStatusToText = "Remotely Paused" 63. Case fileTransferStatusCancelled 64. FTStatusToText = "Cancelled" 65. Case fileTransferStatusCompleted 66. FTStatusToText = "Completed" 67. Case fileTransferStatusFailed 68. FTStatusToText = "Failed" 69. End Select 70. 71. End Function ここで、API_CALLBACK.exe は、以下の VB.NET で作成したものです。 フォームは使わずに、目的の処理が済むと即終了します 要するに、ApplicationEvents.vb を使っています。 実装方法は こちらを参照して下さい 001. Imports System.Runtime.InteropServices 002. Imports System.Text 003. 004. Namespace My 005. 006. Partial Friend Class MyApplication 007. 008. ' ****************************************************** 009. ' Callback 関数の定義( 通常 ) 010. ' ****************************************************** 011. Public Delegate Function EnumWindowsCallbackNormal( _ 012. ByVal hWnd As Integer , _ 013. ByVal lParam As Integer ) As Boolean 014. ' ****************************************************** 015. ' Callback 呼び出し 関数の定義 016. ' ****************************************************** 017. <dllimport( "user32.dll" , charset:= "CharSet.Auto)" > _ 018. Public Shared Function EnumWindows( _ 019. ByVal callback As EnumWindowsCallbackNormal, _ 020. ByVal lParam As Integer ) As Integer 021. End Function 022. 023. ' ****************************************************** 024. ' 情報取得用 API 025. ' ****************************************************** 026. <dllimport( "user32.dll" , charset:= "CharSet.Auto)" > _ 027. Public Shared Function ShowWindow( ByVal hWnd As Integer , _ 028. ByVal nCmdShow As Integer _ 029. ) As Integer 030. End Function 031. 032. <dllimport( "user32.dll" , charset:= "CharSet.Auto)" > _ 033. Public Shared Function GetWindowText( ByVal hWnd As Integer , _ 034. ByVal lpString As StringBuilder, _ 035. ByVal nMaxCount As Integer ) As Integer 036. End Function 037. 038. <dllimport( "user32.dll" , charset:= "CharSet.Auto)" > _ 039. Public Shared Function GetClassName( ByVal hwnd As Integer , _ 040. ByVal lpClassName As StringBuilder, _ 041. ByVal cch As Integer ) As Integer 042. End Function 043. 044. Const STRING_BUFFER_LENGTH As Integer = 255 045. 046. ' ****************************************************** 047. ' 開始( 処理後終了 ) 048. ' ****************************************************** 049. Private Sub MyApplication_Startup( ByVal sender As Object , _ 050. ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me .Startup 051. 052. ' Callback 関数のアドレスの渡し方 053. Dim func As EnumWindowsCallbackNormal = _ 054. AddressOf ActiveProcessListNormal 055. 056. EnumWindows( _ 057. CType ( _ 058. AddressOf ActiveProcessListNormal, _ 059. EnumWindowsCallbackNormal _ 060. ), 0) 061. 062. e.Cancel = True 063. 064. End Sub 065. 066. ' ****************************************************** 067. ' Callback 関数( 通常 ) 068. ' ****************************************************** 069. Private Function ActiveProcessListNormal( ByVal hWnd As Integer , _ 070. ByVal lParam As Integer ) As Boolean 071. 072. Dim windowText As New StringBuilder(STRING_BUFFER_LENGTH) 073. Dim className As New StringBuilder(STRING_BUFFER_LENGTH) 074. 075. GetWindowText(hWnd, windowText, STRING_BUFFER_LENGTH) 076. GetClassName(hWnd, className, STRING_BUFFER_LENGTH) 077. 078. Dim target As String = windowText.ToString() + "" 079. 080. If target.Length >= 5 Then 081. If target.Substring(0, 5) = "Skype" Then 082. 083. If target.IndexOf( "ファイルを受信しています" ) >= 0 Then 084. 085. Console.WriteLine( _ 086. String .Format( "{0}|{1}|{2}" , _ 087. windowText.ToString(), _ 088. className.ToString(), _ 089. hWnd.ToString()) _ 090. ) 091. 092. ShowWindow(hWnd, 9) 093. 094. End If 095. End If 096. End If 097. 098. Return True 099. 100. End Function 101. 102. End Class 103. 104. End Namespace 105. </dllimport( "user32.dll" ,></dllimport( "user32.dll" ,></dllimport( "user32.dll" ,></dllimport( "user32.dll" ,> |