Process.Start - example doesn't work 
Author Message
 Process.Start - example doesn't work

Why doesn't this work?  The example comes straight from the MSDN library, at
http://www.*-*-*.com/
frlrfsystemdiagnosticsprocessclassstarttopic.asp

Sub Main()

' Declare and instantiate a new process component.
Dim myProc As System.Diagnostics.Process
myProc = New System.Diagnostics.Process()

' Do not receive an event when the process exits.
myProc.EnableRaisingEvents = False

' Start Notepad, and assign it to the process component.
myProc.Start("Notepad.exe")

' This prevents the window from accepting a close before it has
' fully opened.
myProc.WaitForInputIdle()

End Sub

I'm using Windows 2000 Pro, and Visual Basic .NET standard 2002.

A window with Notepad appears, and then I get this at the WaitForInputIdle
method:

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.dll

Additional information: No process is associated with this object.

Of course, the ProcessID is 0 at this point.  What's wrong with this
picture?

Thanks.

David Walker



Sun, 28 Aug 2005 04:34:19 GMT  
 Process.Start - example doesn't work
Ok, it's a documentation bug :)

my comments inline following ***

The code in the provided link:

 Private Sub StartWithFileName()
     ' Declare and instantiate a new process component.
     Dim myproc As System.Diagnostics.Process
     myproc = New System.Diagnostics.Process    ' *** we're creating a
process instance

     ' Do not receive an event when the process exits.
     myproc.EnableRaisingEvents = False        ' *** we're seting an
instance member's property
     ' Start Notepad, and assign it to the process component.
     myproc.Start("Notepad.exe")        '*** we're calling a shared method
that returns a new process instance and disregarding that
                                                          ' ***instance.
Also since it's shared, it has no way of accessing the instance from which
it
                                                        '*** was called; in
other words the code before this isn't doing a thing.

     ' This prevents the window from accepting a close before it has
     ' fully opened.
     myproc.WaitForInputIdle    'since this is the original instance (NOT
the process that is running notepad), it's not running and will correctly
throw the exception you saw.

 End Sub

My suggestion: use the code provided in the sample:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...
frlrfsystemdiagnosticsprocessclassstarttopic.asp

Or if you do not care about doing the preparation work for enable raising
events just use the following code:
' Declare a process component.

Dim myProc As System.Diagnostics.Process

' Start Notepad, and assign it to the process component.

myProc = System.Diagnostics.Process.Start("Notepad.exe")

' This prevents the window from accepting a close before it has

' fully opened.

myProc.WaitForInputIdle()

Just to warn, the sample in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...
frlrfsystemdiagnosticsprocessclassstarttopic.asp
has the same issue with the first half of the code being essencially
useless - I'll be entering bugs for these code samples

Sorry for the bug, and hope that helps
Alex
MS VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

___

Quote:
> Why doesn't this work?  The example comes straight from the MSDN library,
at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...
Quote:
> frlrfsystemdiagnosticsprocessclassstarttopic.asp

> Sub Main()

> ' Declare and instantiate a new process component.
> Dim myProc As System.Diagnostics.Process
> myProc = New System.Diagnostics.Process()

> ' Do not receive an event when the process exits.
> myProc.EnableRaisingEvents = False

> ' Start Notepad, and assign it to the process component.
> myProc.Start("Notepad.exe")

> ' This prevents the window from accepting a close before it has
> ' fully opened.
> myProc.WaitForInputIdle()

> End Sub

> I'm using Windows 2000 Pro, and Visual Basic .NET standard 2002.

> A window with Notepad appears, and then I get this at the WaitForInputIdle
> method:

> An unhandled exception of type 'System.InvalidOperationException' occurred
> in system.dll

> Additional information: No process is associated with this object.

> Of course, the ProcessID is 0 at this point.  What's wrong with this
> picture?

> Thanks.

> David Walker



Sun, 28 Aug 2005 05:41:57 GMT  
 Process.Start - example doesn't work
Try this way

myProc = Process.Start("Notepad.exe")
myProc.WaitForExit()

HTH

--
Corrado Cavalli [Microsoft MVP]
UGIdotNET - http://www.ugidotnet.org



Sun, 28 Aug 2005 06:04:44 GMT  
 Process.Start - example doesn't work
Ah.  Thanks!!

Your example was exactly what I wanted -- to start a process (actually
calling "cmd.exe" to call "dir", in order to get a sorted directory list
:-)  )  and wait for it to complete.  I'm using WaitforExit.  I didn't want
to use four lines of code (with StartInfo) when one would do!

So it's NOT hard to call a DOS command from VS.NET and wait for it to
complete.

I should have been able to see the documentation error, but I believed the
sample... even after reading the description of Process.Start online at
cpref/html/frlrfsystemdiagnosticsprocessclassstarttopic2.asp.  (You guys
sure like long names.)

I could have used x = myproc.Start("whatever"), even though it would have
been weird.

Shouldn't process.start("something") be invalid?  Since the process object
is ignored?

I got around it using StartInfo, but I don't need events.  I'll change it
back to Start.  Is EnableRaisingEvents set to False when you call the static
overload of Start?

Thanks again!

David Walker

P.S. I put an IDE bug in the IDE ng, and haven't seen a response -- when you
customize the toolbar in VB.NET standard 2002, some choices (like FIND) are
missing, and some (like SET NEXT STATEMENT) appear twice.  Many of the
choices are total mysteries, documented nowhere (as far as I can tell).



Quote:
> Ok, it's a documentation bug :)

> my comments inline following ***

> The code in the provided link:

>  Private Sub StartWithFileName()
>      ' Declare and instantiate a new process component.
>      Dim myproc As System.Diagnostics.Process
>      myproc = New System.Diagnostics.Process    ' *** we're creating a
> process instance

>      ' Do not receive an event when the process exits.
>      myproc.EnableRaisingEvents = False        ' *** we're seting an
> instance member's property
>      ' Start Notepad, and assign it to the process component.
>      myproc.Start("Notepad.exe")        '*** we're calling a shared method
> that returns a new process instance and disregarding that
>                                                           ' ***instance.
> Also since it's shared, it has no way of accessing the instance from which
> it
>                                                         '*** was called;
in
> other words the code before this isn't doing a thing.

>      ' This prevents the window from accepting a close before it has
>      ' fully opened.
>      myproc.WaitForInputIdle    'since this is the original instance (NOT
> the process that is running notepad), it's not running and will correctly
> throw the exception you saw.

>  End Sub

> My suggestion: use the code provided in the sample:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> frlrfsystemdiagnosticsprocessclassstarttopic.asp

> Or if you do not care about doing the preparation work for enable raising
> events just use the following code:
> ' Declare a process component.

> Dim myProc As System.Diagnostics.Process

> ' Start Notepad, and assign it to the process component.

> myProc = System.Diagnostics.Process.Start("Notepad.exe")

> ' This prevents the window from accepting a close before it has

> ' fully opened.

> myProc.WaitForInputIdle()

> Just to warn, the sample in

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> frlrfsystemdiagnosticsprocessclassstarttopic.asp
> has the same issue with the first half of the code being essencially
> useless - I'll be entering bugs for these code samples

> Sorry for the bug, and hope that helps
> Alex
> MS VB Team

> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.

> ___


> > Why doesn't this work?  The example comes straight from the MSDN
library,
> at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > frlrfsystemdiagnosticsprocessclassstarttopic.asp

> > Sub Main()

> > ' Declare and instantiate a new process component.
> > Dim myProc As System.Diagnostics.Process
> > myProc = New System.Diagnostics.Process()

> > ' Do not receive an event when the process exits.
> > myProc.EnableRaisingEvents = False

> > ' Start Notepad, and assign it to the process component.
> > myProc.Start("Notepad.exe")

> > ' This prevents the window from accepting a close before it has
> > ' fully opened.
> > myProc.WaitForInputIdle()

> > End Sub

> > I'm using Windows 2000 Pro, and Visual Basic .NET standard 2002.

> > A window with Notepad appears, and then I get this at the
WaitForInputIdle
> > method:

> > An unhandled exception of type 'System.InvalidOperationException'
occurred
> > in system.dll

> > Additional information: No process is associated with this object.

> > Of course, the ProcessID is 0 at this point.  What's wrong with this
> > picture?

> > Thanks.

> > David Walker



Mon, 29 Aug 2005 07:02:11 GMT  
 Process.Start - example doesn't work
Thanks.  The other reply was also very helpful.  It's the documentation!

David Walker



Quote:
> Try this way

> myProc = Process.Start("Notepad.exe")
> myProc.WaitForExit()

> HTH

> --
> Corrado Cavalli [Microsoft MVP]
> UGIdotNET - http://www.ugidotnet.org



Mon, 29 Aug 2005 07:03:01 GMT  
 Process.Start - example doesn't work
Wait:  You said to use the code at location
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...
frlrfsystemdiagnosticsprocessclassstarttopic2.asp?? That has the same
problem, useless code before the Start call, no?

 Private Sub StartWithArguments()
     ' Declare and instantiate a new process component.
     Dim myproc As System.Diagnostics.Process
     myproc = New System.Diagnostics.Process

     ' Do not receive an event when the process exits.
     myproc.EnableRaisingEvents = False
     ' Start Internet Explorer, passing in a Web page.
     myproc.Start("IExplore.exe", "http://www.microsoft.com")
 End Sub

David Walker



Quote:
> Ok, it's a documentation bug :)

> my comments inline following ***

> The code in the provided link:

>  Private Sub StartWithFileName()
>      ' Declare and instantiate a new process component.
>      Dim myproc As System.Diagnostics.Process
>      myproc = New System.Diagnostics.Process    ' *** we're creating a
> process instance

>      ' Do not receive an event when the process exits.
>      myproc.EnableRaisingEvents = False        ' *** we're seting an
> instance member's property
>      ' Start Notepad, and assign it to the process component.
>      myproc.Start("Notepad.exe")        '*** we're calling a shared method
> that returns a new process instance and disregarding that
>                                                           ' ***instance.
> Also since it's shared, it has no way of accessing the instance from which
> it
>                                                         '*** was called;
in
> other words the code before this isn't doing a thing.

>      ' This prevents the window from accepting a close before it has
>      ' fully opened.
>      myproc.WaitForInputIdle    'since this is the original instance (NOT
> the process that is running notepad), it's not running and will correctly
> throw the exception you saw.

>  End Sub

> My suggestion: use the code provided in the sample:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> frlrfsystemdiagnosticsprocessclassstarttopic.asp

> Or if you do not care about doing the preparation work for enable raising
> events just use the following code:
> ' Declare a process component.

> Dim myProc As System.Diagnostics.Process

> ' Start Notepad, and assign it to the process component.

> myProc = System.Diagnostics.Process.Start("Notepad.exe")

> ' This prevents the window from accepting a close before it has

> ' fully opened.

> myProc.WaitForInputIdle()

> Just to warn, the sample in

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> frlrfsystemdiagnosticsprocessclassstarttopic.asp
> has the same issue with the first half of the code being essencially
> useless - I'll be entering bugs for these code samples

> Sorry for the bug, and hope that helps
> Alex
> MS VB Team

> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.

> ___


> > Why doesn't this work?  The example comes straight from the MSDN
library,
> at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > frlrfsystemdiagnosticsprocessclassstarttopic.asp

> > Sub Main()

> > ' Declare and instantiate a new process component.
> > Dim myProc As System.Diagnostics.Process
> > myProc = New System.Diagnostics.Process()

> > ' Do not receive an event when the process exits.
> > myProc.EnableRaisingEvents = False

> > ' Start Notepad, and assign it to the process component.
> > myProc.Start("Notepad.exe")

> > ' This prevents the window from accepting a close before it has
> > ' fully opened.
> > myProc.WaitForInputIdle()

> > End Sub

> > I'm using Windows 2000 Pro, and Visual Basic .NET standard 2002.

> > A window with Notepad appears, and then I get this at the
WaitForInputIdle
> > method:

> > An unhandled exception of type 'System.InvalidOperationException'
occurred
> > in system.dll

> > Additional information: No process is associated with this object.

> > Of course, the ProcessID is 0 at this point.  What's wrong with this
> > picture?

> > Thanks.

> > David Walker



Mon, 29 Aug 2005 07:39:24 GMT  
 Process.Start - example doesn't work
Well, looks there is a bug with my post also - I meant the code for the
Start with no arguments (using startinfo):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...
frlrfsystemdiagnosticsprocessclassstarttopic1.asp
which you already said in your other post you were using.

Alex
MS VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

___

Quote:
> Wait:  You said to use the code at location

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...
Quote:
> frlrfsystemdiagnosticsprocessclassstarttopic2.asp?? That has the same
> problem, useless code before the Start call, no?

>  Private Sub StartWithArguments()
>      ' Declare and instantiate a new process component.
>      Dim myproc As System.Diagnostics.Process
>      myproc = New System.Diagnostics.Process

>      ' Do not receive an event when the process exits.
>      myproc.EnableRaisingEvents = False
>      ' Start Internet Explorer, passing in a Web page.
>      myproc.Start("IExplore.exe", "http://www.microsoft.com")
>  End Sub

> David Walker



> > Ok, it's a documentation bug :)

> > my comments inline following ***

> > The code in the provided link:

> >  Private Sub StartWithFileName()
> >      ' Declare and instantiate a new process component.
> >      Dim myproc As System.Diagnostics.Process
> >      myproc = New System.Diagnostics.Process    ' *** we're creating a
> > process instance

> >      ' Do not receive an event when the process exits.
> >      myproc.EnableRaisingEvents = False        ' *** we're seting an
> > instance member's property
> >      ' Start Notepad, and assign it to the process component.
> >      myproc.Start("Notepad.exe")        '*** we're calling a shared
method
> > that returns a new process instance and disregarding that
> >                                                           ' ***instance.
> > Also since it's shared, it has no way of accessing the instance from
which
> > it
> >                                                         '*** was called;
> in
> > other words the code before this isn't doing a thing.

> >      ' This prevents the window from accepting a close before it has
> >      ' fully opened.
> >      myproc.WaitForInputIdle    'since this is the original instance
(NOT
> > the process that is running notepad), it's not running and will
correctly
> > throw the exception you saw.

> >  End Sub

> > My suggestion: use the code provided in the sample:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > frlrfsystemdiagnosticsprocessclassstarttopic.asp

> > Or if you do not care about doing the preparation work for enable
raising
> > events just use the following code:
> > ' Declare a process component.

> > Dim myProc As System.Diagnostics.Process

> > ' Start Notepad, and assign it to the process component.

> > myProc = System.Diagnostics.Process.Start("Notepad.exe")

> > ' This prevents the window from accepting a close before it has

> > ' fully opened.

> > myProc.WaitForInputIdle()

> > Just to warn, the sample in

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > frlrfsystemdiagnosticsprocessclassstarttopic.asp
> > has the same issue with the first half of the code being essencially
> > useless - I'll be entering bugs for these code samples

> > Sorry for the bug, and hope that helps
> > Alex
> > MS VB Team

> > --
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.

> > ___


> > > Why doesn't this work?  The example comes straight from the MSDN
> library,
> > at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > > frlrfsystemdiagnosticsprocessclassstarttopic.asp

> > > Sub Main()

> > > ' Declare and instantiate a new process component.
> > > Dim myProc As System.Diagnostics.Process
> > > myProc = New System.Diagnostics.Process()

> > > ' Do not receive an event when the process exits.
> > > myProc.EnableRaisingEvents = False

> > > ' Start Notepad, and assign it to the process component.
> > > myProc.Start("Notepad.exe")

> > > ' This prevents the window from accepting a close before it has
> > > ' fully opened.
> > > myProc.WaitForInputIdle()

> > > End Sub

> > > I'm using Windows 2000 Pro, and Visual Basic .NET standard 2002.

> > > A window with Notepad appears, and then I get this at the
> WaitForInputIdle
> > > method:

> > > An unhandled exception of type 'System.InvalidOperationException'
> occurred
> > > in system.dll

> > > Additional information: No process is associated with this object.

> > > Of course, the ProcessID is 0 at this point.  What's wrong with this
> > > picture?

> > > Thanks.

> > > David Walker



Wed, 31 Aug 2005 04:30:14 GMT  
 Process.Start - example doesn't work
One last suggestion you may be interested in - the Shell command can take a
wait argument now:
Shell("notepad.exe", AppWinStyle.NormalFocus, True)
MsgBox("closed notepad")
Running this code will only show the messagebox after you exit notepad. This
is probably the easiest way to just run a dos command, or any other
program - it is more limited than the process object, but it usually is
sufficient for what I want to do.

Alex
MS VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

___

Quote:
> Ah.  Thanks!!

> Your example was exactly what I wanted -- to start a process (actually
> calling "cmd.exe" to call "dir", in order to get a sorted directory list
> :-)  )  and wait for it to complete.  I'm using WaitforExit.  I didn't
want
> to use four lines of code (with StartInfo) when one would do!

> So it's NOT hard to call a DOS command from VS.NET and wait for it to
> complete.

> I should have been able to see the documentation error, but I believed the
> sample... even after reading the description of Process.Start online at
> cpref/html/frlrfsystemdiagnosticsprocessclassstarttopic2.asp.  (You guys
> sure like long names.)

> I could have used x = myproc.Start("whatever"), even though it would have
> been weird.

> Shouldn't process.start("something") be invalid?  Since the process object
> is ignored?

> I got around it using StartInfo, but I don't need events.  I'll change it
> back to Start.  Is EnableRaisingEvents set to False when you call the
static
> overload of Start?

> Thanks again!

> David Walker

> P.S. I put an IDE bug in the IDE ng, and haven't seen a response -- when
you
> customize the toolbar in VB.NET standard 2002, some choices (like FIND)
are
> missing, and some (like SET NEXT STATEMENT) appear twice.  Many of the
> choices are total mysteries, documented nowhere (as far as I can tell).



> > Ok, it's a documentation bug :)

> > my comments inline following ***

> > The code in the provided link:

> >  Private Sub StartWithFileName()
> >      ' Declare and instantiate a new process component.
> >      Dim myproc As System.Diagnostics.Process
> >      myproc = New System.Diagnostics.Process    ' *** we're creating a
> > process instance

> >      ' Do not receive an event when the process exits.
> >      myproc.EnableRaisingEvents = False        ' *** we're seting an
> > instance member's property
> >      ' Start Notepad, and assign it to the process component.
> >      myproc.Start("Notepad.exe")        '*** we're calling a shared
method
> > that returns a new process instance and disregarding that
> >                                                           ' ***instance.
> > Also since it's shared, it has no way of accessing the instance from
which
> > it
> >                                                         '*** was called;
> in
> > other words the code before this isn't doing a thing.

> >      ' This prevents the window from accepting a close before it has
> >      ' fully opened.
> >      myproc.WaitForInputIdle    'since this is the original instance
(NOT
> > the process that is running notepad), it's not running and will
correctly
> > throw the exception you saw.

> >  End Sub

> > My suggestion: use the code provided in the sample:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > frlrfsystemdiagnosticsprocessclassstarttopic.asp

> > Or if you do not care about doing the preparation work for enable
raising
> > events just use the following code:
> > ' Declare a process component.

> > Dim myProc As System.Diagnostics.Process

> > ' Start Notepad, and assign it to the process component.

> > myProc = System.Diagnostics.Process.Start("Notepad.exe")

> > ' This prevents the window from accepting a close before it has

> > ' fully opened.

> > myProc.WaitForInputIdle()

> > Just to warn, the sample in

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > frlrfsystemdiagnosticsprocessclassstarttopic.asp
> > has the same issue with the first half of the code being essencially
> > useless - I'll be entering bugs for these code samples

> > Sorry for the bug, and hope that helps
> > Alex
> > MS VB Team

> > --
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.

> > ___


> > > Why doesn't this work?  The example comes straight from the MSDN
> library,
> > at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > > frlrfsystemdiagnosticsprocessclassstarttopic.asp

> > > Sub Main()

> > > ' Declare and instantiate a new process component.
> > > Dim myProc As System.Diagnostics.Process
> > > myProc = New System.Diagnostics.Process()

> > > ' Do not receive an event when the process exits.
> > > myProc.EnableRaisingEvents = False

> > > ' Start Notepad, and assign it to the process component.
> > > myProc.Start("Notepad.exe")

> > > ' This prevents the window from accepting a close before it has
> > > ' fully opened.
> > > myProc.WaitForInputIdle()

> > > End Sub

> > > I'm using Windows 2000 Pro, and Visual Basic .NET standard 2002.

> > > A window with Notepad appears, and then I get this at the
> WaitForInputIdle
> > > method:

> > > An unhandled exception of type 'System.InvalidOperationException'
> occurred
> > > in system.dll

> > > Additional information: No process is associated with this object.

> > > Of course, the ProcessID is 0 at this point.  What's wrong with this
> > > picture?

> > > Thanks.

> > > David Walker



Wed, 31 Aug 2005 04:34:06 GMT  
 Process.Start - example doesn't work
I'm really not an expert on the IDE - anyway hitting customize on the
toolbar I seem to find the Find command under the Edit category, using VS
7.0 and in VS 2003 (aka everett or VS7.1). It is possible the IDE guys are
having problems repoing your issue.

Alex
MS VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

___

Quote:
> Ah.  Thanks!!

> Your example was exactly what I wanted -- to start a process (actually
> calling "cmd.exe" to call "dir", in order to get a sorted directory list
> :-)  )  and wait for it to complete.  I'm using WaitforExit.  I didn't
want
> to use four lines of code (with StartInfo) when one would do!

> So it's NOT hard to call a DOS command from VS.NET and wait for it to
> complete.

> I should have been able to see the documentation error, but I believed the
> sample... even after reading the description of Process.Start online at
> cpref/html/frlrfsystemdiagnosticsprocessclassstarttopic2.asp.  (You guys
> sure like long names.)

> I could have used x = myproc.Start("whatever"), even though it would have
> been weird.

> Shouldn't process.start("something") be invalid?  Since the process object
> is ignored?

> I got around it using StartInfo, but I don't need events.  I'll change it
> back to Start.  Is EnableRaisingEvents set to False when you call the
static
> overload of Start?

> Thanks again!

> David Walker

> P.S. I put an IDE bug in the IDE ng, and haven't seen a response -- when
you
> customize the toolbar in VB.NET standard 2002, some choices (like FIND)
are
> missing, and some (like SET NEXT STATEMENT) appear twice.  Many of the
> choices are total mysteries, documented nowhere (as far as I can tell).



> > Ok, it's a documentation bug :)

> > my comments inline following ***

> > The code in the provided link:

> >  Private Sub StartWithFileName()
> >      ' Declare and instantiate a new process component.
> >      Dim myproc As System.Diagnostics.Process
> >      myproc = New System.Diagnostics.Process    ' *** we're creating a
> > process instance

> >      ' Do not receive an event when the process exits.
> >      myproc.EnableRaisingEvents = False        ' *** we're seting an
> > instance member's property
> >      ' Start Notepad, and assign it to the process component.
> >      myproc.Start("Notepad.exe")        '*** we're calling a shared
method
> > that returns a new process instance and disregarding that
> >                                                           ' ***instance.
> > Also since it's shared, it has no way of accessing the instance from
which
> > it
> >                                                         '*** was called;
> in
> > other words the code before this isn't doing a thing.

> >      ' This prevents the window from accepting a close before it has
> >      ' fully opened.
> >      myproc.WaitForInputIdle    'since this is the original instance
(NOT
> > the process that is running notepad), it's not running and will
correctly
> > throw the exception you saw.

> >  End Sub

> > My suggestion: use the code provided in the sample:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > frlrfsystemdiagnosticsprocessclassstarttopic.asp

> > Or if you do not care about doing the preparation work for enable
raising
> > events just use the following code:
> > ' Declare a process component.

> > Dim myProc As System.Diagnostics.Process

> > ' Start Notepad, and assign it to the process component.

> > myProc = System.Diagnostics.Process.Start("Notepad.exe")

> > ' This prevents the window from accepting a close before it has

> > ' fully opened.

> > myProc.WaitForInputIdle()

> > Just to warn, the sample in

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > frlrfsystemdiagnosticsprocessclassstarttopic.asp
> > has the same issue with the first half of the code being essencially
> > useless - I'll be entering bugs for these code samples

> > Sorry for the bug, and hope that helps
> > Alex
> > MS VB Team

> > --
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.

> > ___


> > > Why doesn't this work?  The example comes straight from the MSDN
> library,
> > at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...

- Show quoted text -

Quote:
> > > frlrfsystemdiagnosticsprocessclassstarttopic.asp

> > > Sub Main()

> > > ' Declare and instantiate a new process component.
> > > Dim myProc As System.Diagnostics.Process
> > > myProc = New System.Diagnostics.Process()

> > > ' Do not receive an event when the process exits.
> > > myProc.EnableRaisingEvents = False

> > > ' Start Notepad, and assign it to the process component.
> > > myProc.Start("Notepad.exe")

> > > ' This prevents the window from accepting a close before it has
> > > ' fully opened.
> > > myProc.WaitForInputIdle()

> > > End Sub

> > > I'm using Windows 2000 Pro, and Visual Basic .NET standard 2002.

> > > A window with Notepad appears, and then I get this at the
> WaitForInputIdle
> > > method:

> > > An unhandled exception of type 'System.InvalidOperationException'
> occurred
> > > in system.dll

> > > Additional information: No process is associated with this object.

> > > Of course, the ProcessID is 0 at this point.  What's wrong with this
> > > picture?

> > > Thanks.

> > > David Walker



Wed, 31 Aug 2005 04:40:12 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. ANOTHER help example doesn't work

2. Microsoft example doesn't work

3. Microsoft example doesn't work...

4. dotnetfx.exe bootstrapper example setup.exe doesn't work

5. DragIcon Property Problem /VB Example Doesn't work

6. Why doesn't MSDN ListView examples work?

7. StandardIn to a process doesn't work

8. terminate process doesn't work.

9. fRefreshLinks Doesn't work if path doesn't exist

10. Windows Service Calling VB6 dll doesn't work but works with VB6

11. IE3 doesn't work after working with webbrowser control

12. Why LoadPicture() works on local pathes and doesn't work on the URLS

 

 
Powered by phpBB® Forum Software