This is the sample code that I used to run another application inside a picturebox:
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll")> Public Shared Function SetParent(ByVal hwndChild As IntPtr, ByVal hwndNewParent As IntPtr) As Integer
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Process1 As New Process
Process1.StartInfo.FileName = "notepad.exe"
Process1.Start()
Do Until Process1.WaitForInputIdle = True
Application.DoEvents()
Loop
SetParent(Process1.MainWindowHandle, PictureBox1.Handle)
End Sub
End Class
Thus, I was able to host another application inside my VB2010 WindowsForm and it works fine. But the problem is, in Windows7, Windows would ask for the permission(whether you want to allow the EXE to run or not). After clicking the “Allow” button, the exe application would open on it’s own window rather than as a child of the PictureBox
I think when Windows asks for the permission, it is skipping the SetParent() API call. I really appreciate any suggestions.
Thanks 🙂
Sorry for the delay in posting the solution. EdgeMeal from VBForums.com had helped me in finding a workaround to this issue. You could view the details here: thread at vbforums.com
And for elevating the permission, that is to ask for the Admin permission when the application starts, we need to change the
requestedExecutionLevelvalue. To change this, goto the project properties(Project menu –> Properties). Then from theApplicationtab, click on theView Windows Settingsbutton. This will open theapp.manifestfile. In this, change the following line(uncommented line):to:
This will ask the Admin permission whenever you run the application. Even when you run it from IDE, it will ask for re-opening the IDE with the Admin privilege.
BTW, I assumed that you would be using VB2010. The above steps are for VB2010(not sure whether it would be same for other versions also).
Hope it helps to someone who is fighting with the same issue. 🙂