Click here to Skip to main content
16,018,650 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to open Windows Explorer and then wait for the user to close this application, before continuing with my program.

The program works as intended with Notepad, but not Explorer.

Thanks

What I have tried:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim newProc As Diagnostics.Process
        'newProc = Diagnostics.Process.Start("Notepad.exe") ' This Works
        newProc = Diagnostics.Process.Start("Explorer.exe") ' This does not work
        newProc.WaitForExit()
        MsgBox("Continue Processing")
    End Sub
Posted
Updated 26-May-17 16:56pm

1 solution

That's because Explorer only ever launches once and stays running the entire time the user is logged in at the console. When you launched your instance of Explorer, you didn't really launch a new process called "Explorer.exe". You told the existing Explorer instance to open your new window.
 
Share this answer
 
v2
Comments
Member 914236 27-May-17 2:00am    
Thanks for explaining why my code does not work.
Is there any way in which I can detect when the user closes the Explorer window / instances that the program opened?
Dave Kreskowiak 27-May-17 10:37am    
There is no built-in method of doing so, no. You'd have to launch the Explorer window, then enumerate the Shell windows and constantly do so, tracking which which window is yours (YOU WILL NOT HAVE 100% ACCURACY!), and wait for the window to disappear. This requires your code to "poll" for this.

Since you're launching an external "process" you will have no control over what the user does with this window. I really have to question why you're even launching an Explorer window in the first place since you cannot control it and you're depending on it as part of your business process.
Member 914236 27-May-17 18:15pm    
The application allows the user to link a file (document) to an accounting transaction.
I give the user the option to create sub-folders,copy, move and re-name files by clicking on a button to open Express.
When complete the user simply closes express to return to the program. This all works without a hitch until the user returns to the program.
At this point the program must refresh a screen to reflect the changes the user might have made using explorer - eg changed file name.
My current solution is to show a flashing refresh button when launching explorer. As Explorer hides the program form the user only sees the refresh button once explorer is closed.
Dave Kreskowiak 27-May-17 18:47pm    
You can all of that in an OpenFileDialog.

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