Starting process using shell execute returns nothing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

dim FileName as string = "Test.doc"
dim P as Process = Process.Start(FileName)
'--P is NOTHING even though document opens!!!

dim Q as new process
Q.StartInfo.FileName = FileName
P = Q.start
'--P is nothing here, either

WHY????
 
Did you try this code?

Dim q As Process

q = Process.Start("C:\windows\Notepad.exe")
q.WaitForExit()
Console.WriteLine("Exit Time:" & q.ExitTime)
 
That would work fine because you are launching an executable. By launching a
..doc file it uses ShellExecute and does not seem to return a process. This
is what I don't get.
 
As far as I can tell, since vb2003. you can use the 'proccess.start' method
to launch any program with it's dedicated exe.

For example

Dim q As New Process

Dim ofd As New OpenFileDialog

ofd.Filter = "Doc Files|*.doc"
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
q = Process.Start(ofd.FileName)

Console.WriteLine("Process Name:" & q.ProcessName)
q.WaitForExit()
End If

Console.WriteLine("Exit Time:" & q.ExitTime)

Console wrote:
Process Name:WINWORD
Exit Time:10/18/2006 10:11:14 PM
 
Yes, the program starts. That is not the problem. I'm trying to get
notified when the user closes down the launched window. To do that I need
the process to exist so it can raise the exited event, but the process
returned after the launch takes plase is NOTHING, so I can't catch the event.

Sorry, I guess I was not clear enough.
 
Back
Top