process.start

.paul.

Well-known member
Joined
May 22, 2007
Messages
212
Programming Experience
1-3
how do i run paint.exe with process.start specifying a file to open?

p.s. paint isn't my default image viewer
 
how do i run paint.exe with process.start specifying a file to open?

p.s. paint isn't my default image viewer

Hi there,

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Process.Start("C:\WINDOWS\system32\mspaint.exe", "C:\Ice-128x128.JPG")
    End Sub
Just specify the application then the file in the arguments.

Regards

Alex
 
why doesn't process.start recognise my filename?

VB.NET:
dim filename as string = "c:\documents and settings\test.bmp"
System.Diagnostics.Process.Start("mspaint.exe", fileName)
 
This works.:)
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim filename As String = "c:\documents and settings\test.bmp"
        System.Diagnostics.Process.Start("mspaint.exe", Chr(34) & filename & Chr(34))
    End Sub

Hope it helps

Alex
 
why doesn't process.start recognise my filename?

VB.NET:
dim filename as string = "c:\documents and settings\test.bmp"
System.Diagnostics.Process.Start("mspaint.exe", fileName)
It's got nothing to do with Process.Start. The second parameter is just a string which is appended to the commandline when the file is executed. Just as when you run a commandline yourself, if you want a value that contains spaces to be treated as a single argument then you have to enclose it in double quotes. Chr(34) will work fine, but there's no reason not to just use literal double quotes:
VB.NET:
Process.Start("mspaint", """" & filename & """")
 
shouldn't that be """ andnot """"?
No it shouldn't. Try putting three double quotes together and see what the IDE tells you. It cause a syntax error. If you want to include double quotes in string literals you must escape them with a second double quote, to indicate that it is a literal character and not the string terminator.
 
Back
Top