Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Shell.Application Open method doesn't seem to

Reply
 
Old 08-22-2008   #1 (permalink)
Bob Bridges


 
 

Shell.Application Open method doesn't seem to

I have a daily task that involves using an Access database, a .txt file in
Notepad and a folder, the same ones each day. I've written a few VBS
programs but I'm trying to learn more. So I set out to write myself a simple
VBS to open all three for me each time. But it seems each of the supposedly
simple steps presents me with an unexpected difficulty. Let's talk about the
folder: I did some searches and thought this looked like the most obvious
way to do it:

set objShell = CreateObject("Shell.Application")
objShell.Open("C:\Path\MorePath\YetMorePath")

That, at least, seems to be what the documentation says about it. And
indeed some of the other methods for Shell.Application seem to work as
advertised - but when I try Open or Explore, I get no response at all, even
to a non-existent path.

Yet I see replies in this forum that recommend exactly this code. Is it a
matter of a Control-Panel setting, perhaps? Why am I getting no open folder,
nor indeed any response at all that I can detect?

My System SpecsSystem Spec
Old 08-22-2008   #2 (permalink)
mayayana


 
 

Re: Shell.Application Open method doesn't seem to

> set objShell = CreateObject("Shell.Application")
Quote:

> objShell.Open("C:\Path\MorePath\YetMorePath")
>
It should work, although the standard way to call
a method that's not a function is without parentheses:

Return = Obj.DoSomething(parameter1)
OR
Obj.DoSomething parameter1

Nevertheless, your version works for me. You can
also use the WScript.Shell Run method to open a folder:

Set SH = CreateObject("WScript.Shell")
SH.Run "C:\Path\MorePath\YetMorePath"

But I just found a very strange thing. I just tried opening
a folder path with a space: "c:\windows\desktop\new folder"

In single quotes Shell.App Open will open in while WScript.Run
shows an error: "Can't find the file specified." On the other hand,
if I wrap the path in triple quotes:

"""c:\windows\desktop\new folder"""

then Run works to open the folder while the Open method
shows no response at all, just as you're describing! I have
no idea of the reason for that.
Quote:

> That, at least, seems to be what the documentation says about it. And
> indeed some of the other methods for Shell.Application seem to work as
> advertised - but when I try Open or Explore, I get no response at all,
even
Quote:

> to a non-existent path.
>
> Yet I see replies in this forum that recommend exactly this code. Is it a
> matter of a Control-Panel setting, perhaps? Why am I getting no open
folder,
Quote:

> nor indeed any response at all that I can detect?

My System SpecsSystem Spec
Old 08-22-2008   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Shell.Application Open method doesn't seem to


"mayayana" <mayaXXyana@xxxxxx> wrote in message
news:%23tsfWjLBJHA.5964@xxxxxx
Quote:

>
> But I just found a very strange thing. I just tried opening
> a folder path with a space: "c:\windows\desktop\new folder"
>
> In single quotes Shell.App Open will open in while WScript.Run
> shows an error: "Can't find the file specified." On the other hand,
> if I wrap the path in triple quotes:
>
> """c:\windows\desktop\new folder"""
>
> then Run works to open the folder while the Open method
> shows no response at all, just as you're describing! I have
> no idea of the reason for that.
>
My guess is that the Open method expects one parameter which is a file
system path. Even if the path has spaces, it handles the value as one path.
The Run method expects something to be executed, which might have
parameters. If there are spaces in the path, it must be enclosed in quotes.
Quotes in a quoted string must be doubled.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 08-22-2008   #4 (permalink)
Richard Mueller [MVP]


 
 

Re: Shell.Application Open method doesn't seem to


"Bob Bridges" <BobBridges@xxxxxx> wrote in message
news:80830453-464A-41AC-8596-9F7488940CF3@xxxxxx
Quote:

>I have a daily task that involves using an Access database, a .txt file in
> Notepad and a folder, the same ones each day. I've written a few VBS
> programs but I'm trying to learn more. So I set out to write myself a
> simple
> VBS to open all three for me each time. But it seems each of the
> supposedly
> simple steps presents me with an unexpected difficulty. Let's talk about
> the
> folder: I did some searches and thought this looked like the most obvious
> way to do it:
>
> set objShell = CreateObject("Shell.Application")
> objShell.Open("C:\Path\MorePath\YetMorePath")
>
> That, at least, seems to be what the documentation says about it. And
> indeed some of the other methods for Shell.Application seem to work as
> advertised - but when I try Open or Explore, I get no response at all,
> even
> to a non-existent path.
>
> Yet I see replies in this forum that recommend exactly this code. Is it a
> matter of a Control-Panel setting, perhaps? Why am I getting no open
> folder,
> nor indeed any response at all that I can detect?
You can use ADO in a VBScript program to run T-SQL statements, like queries,
against an Access database. For example I use code similar to below:
=============
strDBPath = "c:\Scripts\MyDatabase.mdb"
strConnect = "DRIVER=Microsoft Access Driver (*.mdb);" _
& "FIL=MS Access;DriverId=25;DBQ=" & strDBPath & ";"

strSQL = "SELECT Field1, Field2 FROM MyTable WHERE Field3 = 'Value'"

Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.ConnectionString = strConnect
adoConnection.Open

Set adoRecordset = CreateObject("ADODB.Recordset")
Set adoRecordset.ActiveConnection = adoConnection
adoRecordset.Source = strSQL
adoRecordset.Open

Do Until adoRecordset.EOF
strValue1 = adoRecordset.Fields("Field1").Value
strValue2 = adoRecordset.Fields("Field2").Value
Wscript.Echo strValue1 & "," & strValue2
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 08-23-2008   #5 (permalink)
Bob Bridges


 
 

Re: Shell.Application Open method doesn't seem to

Thanks, but it's not just the data but the database itself I want; I've
written an app, with with a dozen forms, buttons, record filters, everything.
It's my contact database.

But that's in the next question; you guys answered this one already, and
thanks very much!

--- "Richard Mueller [MVP]" wrote:
Quote:

> You can use ADO in a VBScript program to run T-SQL statements, like queries,
> against an Access database....
>
> "Bob Bridges" <BobBridges@xxxxxx> wrote in message
> news:80830453-464A-41AC-8596-9F7488940CF3@xxxxxx
Quote:

> >I have a daily task that involves using an Access database, a .txt file in
> > Notepad and a folder, the same ones each day. I've written a few VBS
> > programs but I'm trying to learn more. So I set out to write myself a
> > simple VBS to open all three for me each time. But it seems each of the
> > supposedly simple steps presents me with an unexpected difficulty....
My System SpecsSystem Spec
Old 08-23-2008   #6 (permalink)
Bob Bridges


 
 

Re: Shell.Application Open method doesn't seem to

Aha! The actual path I want, I'm pretty sure, has a folder with a space in
it. I never thought of that, which is kind of dumb because I know quotes are
required for such a path in many other contexts. Thanks much!

--- "mayayana" wrote:
Quote:

> It should work...your version works for me....But I just found a very strange
> thing. I just tried opening a folder path with a space: "c:\windows\desktop\new
> folder". In single quotes Shell.App Open will open in while WScript.Run
> shows an error: "Can't find the file specified." On the other hand,
> if I wrap the path in triple quotes:
>
> """c:\windows\desktop\new folder"""
>
> then Run works to open the folder while the Open method
> shows no response at all, just as you're describing! I have
> no idea of the reason for that.
My System SpecsSystem Spec
Old 08-23-2008   #7 (permalink)
Stefan Kanthak


 
 

Re: Shell.Application Open method doesn't seem to

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote:

Your mail "address" doesnt denote a mailbox!
Quote:

>
> "mayayana" <mayaXXyana@xxxxxx> wrote in message
> news:%23tsfWjLBJHA.5964@xxxxxx
Quote:

>>
>> But I just found a very strange thing. I just tried opening
>> a folder path with a space: "c:\windows\desktop\new folder"
>>
>> In single quotes Shell.App Open will open in while WScript.Run
>> shows an error: "Can't find the file specified." On the other hand,
>> if I wrap the path in triple quotes:
>>
>> """c:\windows\desktop\new folder"""
>>
>> then Run works to open the folder while the Open method
>> shows no response at all, just as you're describing! I have
>> no idea of the reason for that.
>>
>
> My guess is that the Open method expects one parameter which is a file
> system path. Even if the path has spaces, it handles the value as one path.
CreateObject("Shell.Application").Open() uses the Shell (Explorer.exe)
to execute the "Open" verb of the application associated/registered
with the file(system- or shell-object) passed to it, i.e. it relies on
ShellExecute(), which then constructs the commandline resp. calls
CreateProcess().
Quote:

> The Run method expects something to be executed, which might have
> parameters. If there are spaces in the path, it must be enclosed in quotes.
> Quotes in a quoted string must be doubled.
WShell.Run() apparently wraps CreateProcess(), which but uses an UGLY
method to find an executable if you do not quote pathname(s) with
spaces properly: <http://msdn.microsoft.com/en-us/library/ms682425.aspx>
(where ShellExecute() is discussed too).

Stefan

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
shell.application VB Script
Shell.Application/copyTo(): confirmAll option VB Script
Shell.Application copy problems VB Script
can shell.application do this? PowerShell
problem with shell.application PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46