Minimaze Application Window and Open Another Window

I'm running  a WinForms application  in windows7 OS that has two active windows and need to know how to accomplish this; How can I run from Active Window(1) a Shell -PowerShell script to minimize the window of this application where the Shell script will be run by clicking a command bottom and reopen (Maximize) the same application Window(2) that has been minimized before.

Thanks in advance...
Akire4Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
Let me get this straight you have a windows form application that creates a child window. and you want to minimize the parent window? all from a powershell script that runs externally to the application?
Akire4Author Commented:
Yes, thanks for commenting to my question. I have an application that has a wizard type way of configuring the Forms functionality with controls that have some properties open to customize the Forms and I need someway of; when the application (it opens two Windows) opens from inside that application click a button to Minimize the Current active Form and maximize the other application window. This command button have two fields Command and Command Arguments to put a Shell.
Akire4Author Commented:
<you want to minimize the parent window?>
Yes, minimize Parent Window and maximize Child Window

<all from a powershell script that runs externally to the application? >
Yes, if I can call it from a command button inside this application and run a .PS1 file storage on the computer directory and...

No, if it can be run from inside this application Windows Form that have a command button that accept a Shell command Shell and Command Arguments.
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Akire4Author Commented:
Im running an Application that opens two windows  and what I'm trying to accomplish is that when clicking a button on AppInstance_1 it will  minimized it and Maximize AppInstance_2 and vice versa

These sample code below can minimize Notepad, so how can I adapt this code to, let say I have tow Notepad files; File1.txt and file2.txt, how can modify the code below to when run minimize file1.txt and maximaze File2.txt. How can I reference the specific Instance name and not the application?

$sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32
$hwnd = @(Get-Process Notepad)[0].MainWindowHandle
[Win32.NativeMethods]::ShowWindowAsync($hwnd, 2)

Open in new window

Akire4Author Commented:
Can somebody tell me if I'm on the right Forum section???
David Johnson, CD, MVPOwnerCommented:
this is a non trivial question. You have to (a) get all processes that match something and then the problem is which one to maximize and then minimize all the other instances.
import system.linq
Dim procExists as Boolean = Process.GetProcesses().Any(Function(p) p.Name.Contains(processName))

Open in new window

to link through all processes
For Each p As Process In Process.GetProcesses()
   Debug.WriteLine(p.ProcessName)
Next

Open in new window

P/invoke with 'ShowWindow':

\\\
Imports System.Diagnostics
..
..
..
Private Declare Function ShowWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nCmdShow As SHOW_WINDOW _
) As Boolean

<Flags()> _
Private Enum SHOW_WINDOW As Integer
SW_HIDE = 0
SW_SHOWNORMAL = 1
SW_NORMAL = 1
SW_SHOWMINIMIZED = 2
SW_SHOWMAXIMIZED = 3
SW_MAXIMIZE = 3
SW_SHOWNOACTIVATE = 4
SW_SHOW = 5
SW_MINIMIZE = 6
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_RESTORE = 9
SW_SHOWDEFAULT = 10
SW_FORCEMINIMIZE = 11
SW_MAX = 11
End Enum

Private Sub MaximizeAllNotepads()
For Each p As Process In Process.GetProcessesByName("notepad")
ShowWindow(p.MainWindowHandle, SHOW_WINDOW.SW_MAXIMIZE)
Next p
End Sub
///

Open in new window

http://bit.ly/1O0PCBw

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Akire4Author Commented:
David, thanks your contribution to my post.

I'm new to this website, am I in the Scripting/PowerShell Forum?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.