YZlat
asked on
How to stop a process?
I run a process using Process.Start. I wnat to stop that process when application becomes idle or when user clicks END button.
The process I run is simply open a directory on the network:
Process.Start("\\Server\pa th")
The process I run is simply open a directory on the network:
Process.Start("\\Server\pa
ASKER
Bob, I get an error Object reference is not set to an instance of an object in line If Not myProcess.HasExited Then
Even after executing line
myProcess = Process.Start("\\Server\pa th")
myProcess remains null
Even after executing line
myProcess = Process.Start("\\Server\pa
myProcess remains null
It's Fernando; I did not realize that you were opening a Window Explorer window up. The most likely reason it did not return a Process for that is that no new process was stated. When we open a Explorer window it is a child process of explorer.exe and is always running on the system. Do not know how to stop a child process of explorer.
Fernando
Fernando
ASKER
oops, sorry about that...
do you know any other way to open Windows explorer so that it'd be possible to close it programmatically?
do you know any other way to open Windows explorer so that it'd be possible to close it programmatically?
Hi YZlat;
I did come up with a solution to your problem. Open the Windows Explorer window as you did before.
Process.Start("C:Datafiles ")
The when you want to close the window do the following.
Process.Start("C:Datafiles ")
SendKeys.Send("%({F4})")
Now let me explain what is happening here. When you call the window to start a second time it does not start or open a new window but brings the currently opened window to the front. Once the window is in the front of all the other windows you can send that application a Alt+F4 key combo which will close the active window.
Fernando
I did come up with a solution to your problem. Open the Windows Explorer window as you did before.
Process.Start("C:Datafiles
The when you want to close the window do the following.
Process.Start("C:Datafiles
SendKeys.Send("%({F4})")
Now let me explain what is happening here. When you call the window to start a second time it does not start or open a new window but brings the currently opened window to the front. Once the window is in the front of all the other windows you can send that application a Alt+F4 key combo which will close the active window.
Fernando
I re-posted because the path was incorrect.
I did come up with a solution to your problem. Open the Windows Explorer window as you did before.
Process.Start("\\Server\pa th")
The when you want to close the window do the following.
Process.Start("\\Server\pa th")
SendKeys.Send("%({F4})")
Now let me explain what is happening here. When you call the window to start a second time it does not start or open a new window but brings the currently opened window to the front. Once the window is in the front of all the other windows you can send that application a Alt+F4 key combo which will close the active window.
Fernando
I did come up with a solution to your problem. Open the Windows Explorer window as you did before.
Process.Start("\\Server\pa
The when you want to close the window do the following.
Process.Start("\\Server\pa
SendKeys.Send("%({F4})")
Now let me explain what is happening here. When you call the window to start a second time it does not start or open a new window but brings the currently opened window to the front. Once the window is in the front of all the other windows you can send that application a Alt+F4 key combo which will close the active window.
Fernando
ASKER
Fernando, unfortunatelly it didn't work - it opened a new window and did not close it
I put this code inside a click event of a button:
Process.Start("\\Server\pa th")
SendKeys.Send("%({F4})")
I put this code inside a click event of a button:
Process.Start("\\Server\pa
SendKeys.Send("%({F4})")
Hi YZlat;
Did you move the explorer window to a different directory? This is the only reason I can see that would cause this. But in that case it should have open a new Explorer window at the directory \\Server\path and then immediately close it.
Fernando
Did you move the explorer window to a different directory? This is the only reason I can see that would cause this. But in that case it should have open a new Explorer window at the directory \\Server\path and then immediately close it.
Fernando
ASKER
What do you mean by "Did you move the explorer window to a different directory? "? What different directory?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried that but what it does is opens a second window \\Server\path and does not close anything
ASKER
It worked after I declared a global string sPath and used sPath variable instead of "\\Server\path" string in both Process.Start
Thanks!
The only problem is that whenever you open a pth on the network, it creates a pipe on your machine and when folder is closed, the pipe is not destroyed. But if you destroy the pipe, the folder shuts itself down too
Do you know how to close the pipe programmatically? If you do, I will open another question for you
Thanks!
The only problem is that whenever you open a pth on the network, it creates a pipe on your machine and when folder is closed, the pipe is not destroyed. But if you destroy the pipe, the folder shuts itself down too
Do you know how to close the pipe programmatically? If you do, I will open another question for you
No I do not. But I will look around for some info on it.
Fernando
Fernando
Tyr it like this.
Place a class level variable like this in the form code.
Private myProcess As Process
When you start the process do it like this.
myProcess = Process.Start("\\Server\pa
When you want to stop the process then do this.
If Not myProcess.HasExited Then
myProcess.Kill()
End If
Fernando