Public Class Form1 Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr Declare Function SetWiondowText Lib "user32.dll" Alias "SetWindowTextA" ( _ ByVal hWnd As IntPtr, ByVal lpString As String) As Integer Declare Function IsWindow Lib "user32.dll" (ByVal hWnd As IntPtr) As Integer Declare Function SetActiveWindow Lib "user32.dll" (ByVal hWnd As Integer) As Integer Private CplWindowHandle As IntPtr Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Process.Start("inetcpl.cpl") Do '最前のウインドウを取得 CplWindowHandle = GetForegroundWindow If CplWindowHandle <> Me.Handle Then '自分のウインドウでない(コントロールパネル)なら脱出 Exit Do End If 'スリープをかませる Threading.Thread.Sleep(400) Application.DoEvents() Loop Me.Enabled = False WaitForWindowClose(CplWindowHandle) Me.Enabled = True End Sub Private Sub WaitForWindowClose(ByVal hWnd As IntPtr) Do If IsWindow(hWnd) = 0 Then 'ウインドウが存在しないなら脱出 Exit Do End If 'スリープをかませる Threading.Thread.Sleep(400) Application.DoEvents() Loop End Sub End Class