已答覆 Process.Start Issue

  • Wednesday, May 16, 2012 1:40 PM
     
     

    I have an application that that uses process.start.  It works fine on my development machine...but not on an installed machine....at least not for a local file.  The following illustrates my problem...the reference to the url works fine and every time.  However, the reference to the local file may work the First time but on any following attempts will close the application with a WindowsApplication1 error.  Since it can find the file occasionally it is not a file problem.

    Private Sub SimpleButton17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton17.Click
            Dim TextPath As String
            TextPath = Application.StartupPath & "\Text - Typing Legal.doc"
            If System.IO.File.Exists(TextPath) = True Then
                Try
                    System.Diagnostics.Process.Start(TextPath)
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            Else
                MsgBox("No file")
            End If
        End Sub
       

    Private Sub SimpleButton18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton18.Click
            Dim TextPath As String
            TextPath = "http://www.abcnews.com"
            Try
                System.Diagnostics.Process.Start(TextPath)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub

    Does opening Word have something to do with it?

    I'm at a loss...any help would be appreciated.


All Replies

  • Wednesday, May 16, 2012 2:20 PM
    Moderator
     
     

    If the entire application crashes with an unhandled exception then it may be occurring somewhere else...

    Since you have the Process.Start inside a try block, your application should display a message box if that line of code fails.

    You might want to try catching all unhandled exceptions and see if that reveals anything... double click My Project, click the Application tab then click the View Application Events button.  Then use the dropdowns at the top of the code editor to select MyApplication Events on the left and UnhandledException on the right.  Now put a messagebox display in that event handler, recompile and redistribute to your client.  See if you still get a hard crash or if a messagebox pops up now.  If you still get a hard crash I would suspect some kind so software issue on that particular client (have you been able to replicate the issue on a different client machine?).


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Wednesday, May 16, 2012 2:44 PM
     
     
    Not to sound like an idiot...but the Application Events only shows General on the left and Declarations on the right.  Secondly...what code would I place....msgbox(ex.message)?
  • Wednesday, May 16, 2012 3:13 PM
    Moderator
     
     
    Sorry, put your cursor in the in the partial class definition first, then start selecting from the dropdowns.  The code editor will generate the method handler stub into which you place that code.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Wednesday, May 16, 2012 4:05 PM
     
     

    I still can't figure out ... the drop downs just aren't showing anything.

    But on a related note.  I created a simple project with just the process.start code and it works perfectly on the client machine.  In addition...the original code (the one that fails) worked perfectly on another machine.

    I'm baffled...

  • Wednesday, May 16, 2012 4:14 PM
    Moderator
     
      Has Code

    Paste this over the code file VS generated:

    Namespace My
        ' The following events are available for MyApplication:
        ' 
        ' Startup: Raised when the application starts, before the startup form is created.
        ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
        ' UnhandledException: Raised if the application encounters an unhandled exception.
        ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
        ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
        Partial Friend Class MyApplication
            Private Sub MyApplication_UnhandledException(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
                MessageBox.Show(e.Exception.Message)
                'e.ExitApplication = False 
            End Sub
        End Class
    End Namespace

    Uncomment the e.ExitApplication = False line if you want the app to continue after the error.

    However it sounds like you might be facing an issue on that one user's PC if you cannot reproduce it on another machine.  Perhaps they have some funky security software or configuration that is causing you issues (there was a time when McAffee would screw up a .Net TextBox, for instance...).


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Wednesday, May 16, 2012 5:15 PM
     
     

    Assuming I put it in the right spot...I'm still getting an Application failure without any message.  Though I am able to debug and it stops with an Unhandled Exception at 0x74234c99 in the "packagename".  Access violation reading 0x8b55ff8f       then 74234c99 call dword ptr [ecx+4]  

    I have no idea what that stuff means.

    Funny...I have McAffee on that machine...the one that fails.

  • Thursday, May 17, 2012 2:21 AM
     
     

    Just as a test, can you change the path from Application.StartupPath to Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) ?

    Your new TextPath would be Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Text - Typing Legal.doc"

    of course the .doc file needs to be in the My Documents folder for this test to succeed at all.

    I built your code and just copied the executable and a doc file to my Program Files folder - it works properly every time I run it

    the only difference is the filename "Toyota.doc" instead of  "\Text - Typing Legal.doc" - I don't think spaces in the name has any effect.

    Another test would be to start a new project with only the sub that is failing and see if that works consistently.

    Good Luck

  • Thursday, May 17, 2012 2:28 AM
     
     

    See if  you can disable it temporarily (or permanently - replace with something else)........

  • Thursday, May 17, 2012 3:21 PM
     
     

    I tried a TEST and things only get more weird. I created a new startup form with 2 buttons.  The first contains the process.start link I've used above and the other proceeds to the the mainform.  On the new startup form the link works fine every time!!!.  Then when I go to the mainform...the links work fine and every time.  BUT...if I skip hitting the link button on the startup form and proceed directly to the main form the problem persists (works first time and then fails/crashes on the succeeding times).  In a nutshell if I open up process.start prior to my mainform things work fine.  What would explain that?

  • Thursday, May 17, 2012 3:59 PM
    Moderator
     
     

    What does the Form.Load code look like in that "Main Form"?

    Also, for grins, did you try to disable McAffee and see if the problem persists?


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Thursday, May 17, 2012 4:40 PM
     
     

    Good idea.  First...I tried by turning off McAffee...but that didn't help..

    But...my mainform load includes a ton of database stuff where I'm loading data into controls.  I created a dummy button with the above referenced link and exited the formload before the data loads  and it works every time.  Any thoughts why?  I guess I'll try and piece meal the loads and see if one specific control is the issue.

  • Thursday, May 17, 2012 4:50 PM
    Moderator
     
     

    No way to guess without seeing the code.

    However, checking it by adding back small chunks at a time until the error occurs is probably the way to go at this point (as opposed to shotgun-posting the entire routine).


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Thursday, May 17, 2012 6:01 PM
     
     

    I found something but I'm not sure why.  It appears to be in my SQL statement.  It works when I limit the statement to "Select * from Details"  but when I add "where ....".  It fails.  I should add it works fine on my development machine.  Here's the code...

    Dim LXConn As New OleDbConnection(CS)
            LXConn.Open()
            'SQL = "Select * from Details where Active = True order by TestName"
            SQL = "Select * from Details"
            Dim LXCommand As New OleDbCommand(SQL, LXConn)
            Dim LXReader As OleDbDataReader = LXCommand.ExecuteReader
            While (LXReader.Read())
                ListBoxControl2.Items.Add(LXReader("TestName"))
                ListBoxControl3.Items.Add(LXReader("TestName"))
                ListBoxControl4.Items.Add(LXReader("TestName"))
            End While
            LXConn.Close()

    I'm no programming guru especially with databases but not sure why there is any issue...

  • Thursday, May 17, 2012 7:21 PM
    Moderator
     
     

    Yeah that makes no sense...

    It sounds like there is something wrong with this one computer; some kind of corruption in the framework or something...

    It doesn't seem like there's anything to cause the problem in your code, and if you cannot reproduce it outside of this one computer, then I would look at repairing or reloading that one PC.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Thursday, May 17, 2012 8:43 PM
     
     Answered

    I tried it on another computer and it failed intermittently. 

    But I think I solved it.  Instead of loading all the data/controls on form load ... I loaded some later (including the above listboxes).  For some reason now it works perfectly.  I'm not sure why...

  • Friday, May 18, 2012 2:44 PM
     
     
    Thanks for all your assistance...
  • Friday, May 18, 2012 8:04 PM
     
      Has Code

    Please try this class instead:

    Imports System.IO
    Imports System.Diagnostics
    
    Public Class MSWordClass
        Public Shared Sub OpenDoc(ByVal strFileName As String)
            Dim strOfficePath As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) & "\Microsoft Office"
            Dim strWordPath As String = String.Empty
            Dim processWord As New Process()
    
            strWordPath = strOfficePath & "\Office9" & "\winword.exe"
            If File.Exists(strWordPath) Then
                processWord.StartInfo.FileName = strWordPath
            End If
    
            strWordPath = strOfficePath & "\Office9" & "\winword.exe"
            If File.Exists(strWordPath) Then
                processWord.StartInfo.FileName = strWordPath
            End If
    
            strWordPath = strOfficePath & "\Office10" & "\winword.exe"
            If File.Exists(strWordPath) Then
                processWord.StartInfo.FileName = strWordPath
            End If
    
            strWordPath = strOfficePath & "\Office11" & "\winword.exe"
            If File.Exists(strWordPath) Then
                processWord.StartInfo.FileName = strWordPath
            End If
    
            strWordPath = strOfficePath & "\Office12" & "\winword.exe"
            If File.Exists(strWordPath) Then
                processWord.StartInfo.FileName = strWordPath
            End If
    
            strWordPath = strOfficePath & "\Office14" & "\winword.exe"
            If File.Exists(strWordPath) Then
                processWord.StartInfo.FileName = strWordPath
            End If
    
            processWord.StartInfo.Arguments = """" & strFileName & """" 
            processWord.Start()
        End Sub
    End Class

    This class can detect different version of MS Office and hence to invoke the corresponding version of MS Word to open your .doc document.  Use your .doc filename as a argument to pass into the OpenDoc method.


    My blog: http://soho-hsh.blogspot.com


    • Edited by horngsh Friday, May 18, 2012 8:05 PM
    •