I need to write a VB.Net Winform application that is called through Windows’ context menu in Explorer and can take multiple parameters, where the final parameter is the full path to a file with spaces in it.
I tried the following as parameters, to no avail:
This is a test "%1" -> this
"This is a test "%1"" -> This is a test C:\Program
"This is a test" "%1" -> This is a test
"This is a test "%1%"" -> This is a test
Does someone know how to get Windows to pass the full path to the filename?
Thank you.
Windows is passing the full path. You’re just having trouble parsing it.
In the above example, since there are no quotation marks around the words in the phrase “This is a test”, they get passed as separate command line arguments.
In the second example, the quotation marks you inserted before the
%1terminated the first argument, leaving the actual file name unquoted.In the third example, the two arguments are quoted separately, so they arrive cleanly as two arguments to your program. This is the one you should be using. Your problem is that you are looking only at
cmdArgs(0)and ignoring the other stuff in the rest ofcmdArgs. In particular, you forgot to check outcmdArgs(1), which is where the filename is.