try....
When coding start VS as admin.
For compile, set requestedExecutionLevel line in app.manifest to level="requireAdministrator".
Code:' When coding start VS as admin. ' For compile, set requestedExecutionLevel line in app.manifest to level="requireAdministrator". Imports System.Runtime.InteropServices Public Class Form1 <DllImport("user32.dll")> Private Shared Function SetParent(ByVal hwndChild As IntPtr _ , ByVal hwndNewParent As IntPtr) As IntPtr End Function <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> Private Shared Function IsWindow(ByVal hWnd As IntPtr) As Boolean End Function ' variables used to restore launched app Private origOwner As IntPtr = IntPtr.Zero Private app_hWnd As IntPtr = IntPtr.Zero ' launch app, change parent to Me. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim p As New Process p.StartInfo.FileName = "regedit.exe" p.Start() p.WaitForInputIdle(-1) ' wait upto 5 secs to get MainWindowHandle (not zero). For i = 1 To 50 If Not p.MainWindowHandle = IntPtr.Zero Then Exit For End If Threading.Thread.Sleep(100) Next If p.MainWindowHandle = IntPtr.Zero Then MessageBox.Show("Unable to get window handle") Else ' demo limited to one instance, so disable this button! Button1.Enabled = False ' save handle app_hWnd = p.MainWindowHandle ' save current parent/set new parent as Me. origOwner = SetParent(app_hWnd, Me.Handle) End If End Sub Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing ' restore app to original parent (if still running). If Not app_hWnd = IntPtr.Zero Then If IsWindow(app_hWnd) Then SetParent(app_hWnd, origOwner) End If End If End Sub End Class




Reply With Quote