Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2007, 07:36 PM
Authorized User
 
Join Date: Dec 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to maxl
Default Problem using Process class to open MSWord docs

Hey all,

i've got a strange problem that i can't figure out. Im using the process class to create an instance of Process, assign the StartInfo.FileName to a local file (the full path to the file) and then invoke the Start() method to start the process. right after that line i then call the waitforexit() method so my program has to wait for that process to close before it continues. Here is the code:

Code:
Dim fileProcess As New Process

        Try
            Me.Hide()
            fileProcess.StartInfo.FileName = fileOpenPath
            fileProcess.Start()
            fileProcess.WaitForExit()
        Catch ex as Exception
        ...
        End Try
        fileProcess.Dispose()
My problem is that, depending on the system im on, when i open a *.doc file, MS Word 03 opens up and loads the file and right after its finished loading the file and the program execution reaches the line fileProcess.WaitForExit(), the JIT compiler throws an exception stating: "No process is associated with this object." This happends on some systems and works on others (so far). What is happening here? is there something wrong with the code?

 
Old February 8th, 2007, 09:16 PM
Authorized User
 
Join Date: Dec 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to maxl
Default

I just updated my code a little bit because i've been reading that sometimes the mistake is made because the process object is actually empty, but im not sure how this happends. Here is the updated code, please let me know if i'm on the right track and this is/is not correct:
Code:
        Dim si As New ProcessStartInfo(strTmp)
        Dim proc As Process

        Try

            Me.Hide()

            proc = Process.Start(si)
            proc.WaitForExit()
            MessageBox.Show(proc.ExitCode)
            proc.Dispose()
       Catch ...
       End Try
Thank you.

 
Old February 9th, 2007, 08:24 AM
Authorized User
 
Join Date: Nov 2006
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

Is Microsoft Outlook running on the machines that give you the error? Often Outlook is configured to use Word as the email editor which would mean that Word is already present in memory (and will most likely begin loading the document before your process fully starts).

I tested your code on my computer and although I did not get the error message, I was unable to make the VB program wait for the exiting of Word. However, after closing Outlook your code worked perfectly.

As for what you will need to do in these cases, that ball I'm afraid is back in your court.

I hope this helps.



Best Regards,
Earl Francis
 
Old February 12th, 2007, 05:36 PM
Authorized User
 
Join Date: Dec 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to maxl
Default

Thanks for the reply.

at first i ran the program when i knew Outlook was not running, and the code executed fine. i was able to use the WaitForExit() method. after that i started up Outlook then ran the program again, this time it errored out. It didn't give me the exact same error that i have been recieving before which was "No process associated with this object." instead it gave me the error "Ojbect not set to an instance of an object." I guess they kind of mean the same thing but different things are happening here.

Your suggestion however has fixed it for now, thank you! i will update this post if the problem persists.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with process.. nelly78 .NET Framework 2.0 3 October 14th, 2008 05:54 AM
process.startinfo opens new instance of process Anypond General .NET 0 August 28th, 2008 05:35 AM
Process problem wslyhbb C# 2 February 14th, 2006 01:48 AM
Open Office docs to Wiki docs kate XSLT 1 April 18th, 2005 11:47 AM
MsWord PIA Execution Problem alex_read Pro VB.NET 2002/2003 0 November 17th, 2004 04:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.