Joe:
There are 3 static overloads of the Start method in the Process class. Try
those.
Thanks,
Mujtaba.
> I am using the Process class to start the associated program for a specific
> file. The Process.Start method reuses an existing running instance of the
> Process, and that's not want I want. I always want a new unique instance of
> the application to start.
Joe - 20 Dec 2004 16:35 GMT
Thanks, but all of the overloads do the same thing - they reuse a process if
it is already running, and I alwasy want to create an new instance of the
process. I'm trying to display an XML or HTML file in IE (or whatever program
is associated with XML on the user's system). I don't want an existing
instance of IE to load the XML because I want the user to close the
application before returning to my app. Closing an open instance would be a
major annoyance if they want their browse left open.
> Joe:
>
[quoted text clipped - 10 lines]
> of
> > the application to start.
Mujtaba Syed - 20 Dec 2004 17:11 GMT
Hi Joe:
See the example here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemdiagnosticsprocessclassstarttopic.asp
Thanks,
Mujtaba.
> Thanks, but all of the overloads do the same thing - they reuse a process if
> it is already running, and I alwasy want to create an new instance of the
[quoted text clipped - 18 lines]
> > of
> > > the application to start.
Joe:
Try this class:
Imports System.Diagnostics
Imports System.IO
Public Class ShellDocument
Private Declare Function FindExecutable Lib "shell32.dll" Alias
"FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult
As System.Text.StringBuilder) As Integer
Public Shared Function Start(ByVal fileName As String) As Process
Dim sExeName As String = ""
Dim sTempFile As String = Path.GetTempPath() +
Guid.NewGuid.ToString("B") + ".htm"
Dim oFile As New FileStream(sTempFile, IO.FileMode.Create,
IO.FileAccess.Write, IO.FileShare.Write)
Try
Dim oStr As New System.Text.StringBuilder
oStr.Append(Chr(32), 254)
Dim iResult As Integer = FindExecutable(sTempFile, "", oStr)
sExeName = oStr.ToString()
Finally
oFile.Close()
IO.File.Delete(sTempFile)
End Try
Dim info As New System.Diagnostics.ProcessStartInfo(sExeName)
info.Arguments = fileName
Return System.Diagnostics.Process.Start(info)
End Function
End Class
Shariq Khan
shariq@shariqkhan.com
>I am using the Process class to start the associated program for a specific
> file. The Process.Start method reuses an existing running instance of the
> Process, and that's not want I want. I always want a new unique instance
> of
> the application to start.
Joe - 20 Dec 2004 18:49 GMT
This doesn't do it either. I don't want to close the currently running
instance, I want to create my own instance of the app (whatever the
associated program is) and then wait for the user to close it manually.
Thanks though.
> Joe:
>
[quoted text clipped - 41 lines]
> > of
> > the application to start.
Shariq Khan - 20 Dec 2004 19:10 GMT
If you look closely, the function returns a System.Diagnostics.Process
object. You can call the WaitForExit method on that object to wait till that
process closes. See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemdiagnosticsprocessclasswaitforexittopic.asp
You can also setup a handler for the OnExited event on this process object
which will be fired when the process exits.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemdiagnosticsprocessclasswaitforexittopic.asp
Hope this helps.
Cheers,
Shariq Khan
shariq@shariqkhan.com
> This doesn't do it either. I don't want to close the currently running
> instance, I want to create my own instance of the app (whatever the
[quoted text clipped - 50 lines]
>> > of
>> > the application to start.
Joe - 20 Dec 2004 19:10 GMT
Yes, sorry, this does do what I want, thank you.
> Joe:
>
[quoted text clipped - 41 lines]
> > of
> > the application to start.