By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

Shell Function Parameter with Spaces

P: n/a
Hi Friends

I want to launch notepad with a specific file on a
command click event. So I was using the "Shell" function
from VB on a command click event.For ex:

Shell "Notepad.exe C:\Program
Files\Test.txt",VbNormalFocus

But here is the problem in the space of the "Program
Files" folder, ie, "Program[SPACE]Files". The Shell
function not reading any character after the SPACE.

So HOW CAN I Launch my programs which has a SPACE in the
PATH parameter ???

Thanx
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* "Mr Utkal Ranjan" <ut*****@hotmail.com> scripsit:
I want to launch notepad with a specific file on a
command click event. So I was using the "Shell" function
from VB on a command click event.For ex:

Shell "Notepad.exe C:\Program
Files\Test.txt",VbNormalFocus

But here is the problem in the space of the "Program
Files" folder, ie, "Program[SPACE]Files". The Shell
function not reading any character after the SPACE.

So HOW CAN I Launch my programs which has a SPACE in the
PATH parameter ???


Try 'System.Diagnostics.Process.Start'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
> Shell "Notepad.exe C:\Program
Files\Test.txt",VbNormalFocus

But here is the problem in the space of the "Program
Files" folder, ie, "Program[SPACE]Files". The Shell
function not reading any character after the SPACE.


Mr. Wagner's response is probably a better way, but here's the rundown on
the spaces:

When you called shell, you passed it a command line that is interpreted by
the operating system:

Notepad.exe C:\Program Files\Test.txt

According to the way the operating system parses command lines, you have
specified 3 tokens:

1. Notepad.exe
2. C:\Program
3. Files\Test.txt

The operating system recognises the first as a program, finds it in the
path, and executes it, passing the other two tokens as two command line
parameters. Notepad thinks that "c:\program" is the name of the file you
want to open.

To prevent this, any file system references can be enclosed in double quotes
so that the operating system doesn't misinterpret the meaning of the embeded
spaces, like this (you can actually try this in a Start -> Run box):

Notepad.exe "C:\Program Files\Test.txt"

The way you would issue your shell statement to include the quotes as part
of the string is to use two double quotes for each double quote that you
want inside the string:

Dim s As String
s = "Notepad.exe ""C:\Program Files\Test.txt"""
MessageBox.Show(s) 'Note the way the quotes are embedded
Shell(s, AppWinStyle.NormalFocus)

This quote technique works anywhere in Windows where the operating system or
a [well written] program expects a path or filename.
--
Peace & happy computing,

Mike Labosh, MCSD MCT
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei
Nov 20 '05 #3

P: n/a
Thanx yaaar

Its working .....

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.