Shell() using quotes query

K

Ken Miller

Hi all, I'm very new to vb.net, and was trying to write a wrapper for a
command line utility, the problem being the parameter to be called to it is
a path, and will generally have spaces in it. I've tried various things,
using multiple "'s, Chr$(34)s and its making me mad now :)

TextBox1 is the path that I'm sending to the cmd. Really all I want is to
put a pair of quotes around the actual path, so that the data in TextBox1
becomes "C:\test.txt" instead of C:\test.txt or whatever.
Can anyone help?

Heres the bit of code:
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click

If OpenFileDialog1.ShowDialog = DialogResult.OK Then

TextBox1.Text = OpenFileDialog1.FileName

command = Shell("C:\WINDOWS\pscp.EXE " + TextBox1.Text + " " +
TextBox2.Text, AppWinStyle.NormalFocus)

Thanks,

Ken
 
P

Paul R. Sadowski

Ken Miller said:
put a pair of quotes around the actual path, so that the data in TextBox1
becomes "C:\test.txt" instead of C:\test.txt or whatever.

command = Shell("C:\WINDOWS\pscp.EXE " + Chr(34) + TextBox1.Text + Chr(34)
+ " " + TextBox2.Text, AppWinStyle.NormalFocus)
 
K

Ken Miller

command = Shell("C:\WINDOWS\pscp.EXE " + Chr(34) + TextBox1.Text +
Chr(34)
+ " " + TextBox2.Text, AppWinStyle.NormalFocus)
Thanks heaps for that. Everyone I asked was saying Chr$(34) which wasnt
working. Works perfectly now :)

Ken
 
H

Herfried K. Wagner [MVP]

* "Ken Miller said:
Hi all, I'm very new to vb.net, and was trying to write a wrapper for a
command line utility, the problem being the parameter to be called to it is
a path, and will generally have spaces in it. I've tried various things,
using multiple "'s, Chr$(34)s and its making me mad now :)

TextBox1 is the path that I'm sending to the cmd. Really all I want is to
put a pair of quotes around the actual path, so that the data in TextBox1
becomes "C:\test.txt" instead of C:\test.txt or whatever.
Can anyone help?

\\\
.... = _
Shell( _
"C:\WINDOWS\pscp.exe """ & TextBox1.Text & """ """ & TextBox2.Text & """", _
... _
)
///
 
H

Herfried K. Wagner [MVP]

* "Ken Miller said:
Thanks heaps for that. Everyone I asked was saying Chr$(34) which wasnt
working. Works perfectly now :)

Alternatively (more high-level) you could use 'ControlChars.Quote'
instead of 'Chr(34)'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top