Click here to Skip to main content
15,895,812 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I have tried fallowing three different methods, all methods works in my other projects, my current project is a windows service, I'm calling the methods through my class.

When I debug it out I'm not getting exception at any of them !

Try
    Try
        Directory.SetCurrentDirectory("C:\")
        Dim p As New Process
        Dim pi As New ProcessStartInfo
        pi.Verb = "print"
        pi.FileName = FilePATH
        pi.UseShellExecute = True
        p.StartInfo = pi
        p.Start()
    Catch ex As Exception
    End Try
    Try
        System.Diagnostics.Process.Start(FilePATH)
    Catch ex As Exception
    End Try
    Try
        Shell(FilePATH, AppWinStyle.NormalFocus)
    Catch ex As Exception
    End Try
Catch ex As Exception
    MsgBox(ex.Message)
    EventLog.WriteEntry("PEGASUS", "ExecuteFile___" & DateTime.Now & ">>>>" & ex.Message, EventLogEntryType.Warning)
End Try


[edit]Code block added, DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously - OrignalGriff[/edit]

No C# here. Removed bad tag. Toli Cuturicu
Posted
Updated 8-Mar-11 6:10am
v3

It's difficult to tell what is going on, because you are swallowing all exceptions. Either remove your inner try blocks and just leave the outer one, or populate your inner catch blocks and report errors.

As it is, any error will be swallowed and never seen by the reporting catch block.
 
Share this answer
 
Comments
Sandeep Mewara 8-Mar-11 11:17am    
Comment from OP:
thank you for interested i alredy did what u say but nothing different, did not work, did not get exception, i m getting mad at that
Sergey Alexandrovich Kryukov 8-Mar-11 13:15pm    
I am almost sure this is about the path, please see my answer.
Good point about exception blocking! I put my recommendations on proper techniques.
My 5 for you.
--SA
First of all, you need to check batch file path and access this path properly in your application.
You should never assume it is in your working directory, even if you put your file in your executable directory. The working directory totally depends on where your start your executable.

Let's assume you put your file in your executable directory. More exactly, this is the directory of the "main module of entry assembly". This is how to find out its path:

C#
exePath = System.IO.Path.GetDirectoryName(
    System.Reflection.Assembly.GetEntryAssembly().Location);


By the way, Griff is right on exceptions: you should not block exception propagation like you do!
See this:
How do i make a loop that will stop when a scrollbar reaches the bottom[^]
When i run an application an exception is caught how to handle this?[^]
This is also important if you ask a CodeProject Question.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900