Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to open an external exe window (like Notepad) from within a .Net VB application and move it to a specific location.

I am using VS 2011 on Windows 8 x64. The code is not returning any errors, but it is not working.

Here is my code:
VB
<DllImport("user32.dll")> _
   Public Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
   End Function

   Public Sub NoveNotepad()
       Dim ApplicationProcess = System.Diagnostics.Process.Start("Notepad.exe")
       ApplicationProcess.WaitForInputIdle()
       Dim ApplicationHandle = ApplicationProcess.MainWindowHandle
       Dim z = MoveWindow(ApplicationHandle, 600, 600, 600, 600, True) ' THIS RETURNS TRUE
   End Sub

Any ideas?
Posted
Updated 30-Oct-13 21:18pm
v2

1 solution

What is the actual value of the ApplicationHandle when you try to retrieve it? It might be a trust issue: "for full trust for the immediate caller. This member cannot be used by partially trusted code.". Check it out here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx[^]

To simply test if this is the issue, right click your application and execute it as administrator to see if notepad is then moved as you requested. If so, you know what the problem is.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900