473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Shell Function Parameter with Spaces

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
3 11796
* "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
> 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
Thanx yaaar

Its working .....

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Will Seay | last post by:
At the end of this message I've pasted a script we're trying to modify slightly. I don't believe it is VBscript or javascript but these are the closest groups I could find with my limited...
10
by: Nick Craig-Wood | last post by:
I'm trying to avoid using shell metacharacters in os.popen in a portable fashion. os.popen() only seems to take a string as the command which would need tricky quoting. os.popen2() can take a...
4
by: Isaac | last post by:
Hi mates I want to know a simple program of return array from function ? Do I need to use pointer to return the address of the first element in an array. Isaac
8
by: zhiwei wang | last post by:
I remember that there is a function that could invoke shell command such as "rm" "cp", directly in .c file. But I could not recall its name, and I googled with nothing meaningful. I vaguely...
2
by: Robert E. Flaherty | last post by:
I am using System.Data.OracleClient (Oracle Provider for OLE DB 9.2.0.4.0) in an ASP.NET 1.1 app. I am evoking a stored procedure with a number of input parameters and two output parameters, both...
4
by: Ken Miller | last post by:
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....
8
by: Dave G | last post by:
I know this is an old favourite but I can't find a simple answer to a simple question. I'm trying to run this: shell("c:\program files\pkware\pkzipc\pkzipc.exe -ext " & myPath & myZIPFile & "...
8
by: Mike | last post by:
Am trying to open a Microsoft Word .doc file using Access 2000 with Shell function (on Windows XP Operating system) Here is the code : Shell "C:\Program Files\Microsoft...
7
by: =?ISO-8859-2?Q?Gregor_Kova=E8?= | last post by:
Hi! Is it possible to use parameter markers like this: 1.) SELECT * FROM TABLE1 WHERE FIELD1 LIKE '%?%' If I now set parameter 1 to '' (empty string) I don't get any rows back, but if I run:...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.