C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.35068 の関連記事表示

<< 0 >>
■35068  Re[1]: InternetExplorerを強制終了させたい
□投稿者/ 魔界の仮面弁士 -(2009/04/18(Sat) 18:37:59)
    2009/04/18(Sat) 18:47:47 編集(投稿者)

    No35067 (W さん) に返信
    > たとえばButton1を押した後にInternetExplorerを強制終了(タスクマネージャで言うプロセスの終了)をさせたいのですが

    フォームに、ListBox と Button を貼っておいてください。


    Option Strict On
    Imports Item = System.Collections.Generic.KeyValuePair(Of Object, String)
    Imports System.Runtime.InteropServices
    Public Class Form1

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    If ListBox1.SelectedIndex > 0 Then
    CloseIE(ListBox1.SelectedIndex)
    End If
    End Sub

    Private Sub CloseIE(ByVal index As Integer)
    Dim item As Item = DirectCast(ListBox1.Items(index), Item)
    Dim internetExplorer As Object = item.Key
    Dim LocationURL As String = CallByName(internetExplorer, "LocationURL", vbGet).ToString()
    Dim locationName As String = item.Value
    Dim message As String = "ブラウザを閉じますか?" & vbCrLf & locationName & vbCrLf & LocationURL
    If MessageBox.Show(message, "IE終了", MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
    = System.Windows.Forms.DialogResult.Yes Then
    ListBox1.Items.RemoveAt(index)
    CallByName(internetExplorer, "Quit", vbMethod)
    Marshal.ReleaseComObject(internetExplorer)
    End If
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    Dim shellWindows As Object = Activator.CreateInstance( _
    Type.GetTypeFromCLSID(New Guid("{9BA05972-F6A8-11CF-A442-00A0C90A8F39}")))
    Dim cnt As Integer = CInt(CallByName(shellWindows, "Count", vbGet))

    ListBox1.BeginUpdate()
    For c As Integer = 0 To cnt - 1
    Dim internetExplorer As Object = CallByName(shellWindows, "Item", vbMethod, c)
    Dim doc As Object = CallByName(internetExplorer, "Document", vbGet)
    Dim docType As String = TypeName(doc)
    Marshal.ReleaseComObject(doc)
    If docType Like "*HTMLDocument*" Then
    Dim locationName As String = CallByName(internetExplorer, "LocationName", vbGet).ToString()
    ListBox1.Items.Add(New Item(internetExplorer, locationName))
    Else
    Marshal.ReleaseComObject(internetExplorer)
    End If
    Next
    Marshal.ReleaseComObject(shellWindows)
    ListBox1.DisplayMember = "Value"
    ListBox1.EndUpdate()
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
    For Each listItem As Item In ListBox1.Items
    Marshal.ReleaseComObject(listItem.Key)
    Next
    ListBox1.Items.Clear()
    End Sub
    End Class
記事No.35067 のレス /過去ログ61より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -