![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | Re: Shell.Application Open method doesn't seem to > set objShell = CreateObject("Shell.Application") Quote: > objShell.Open("C:\Path\MorePath\YetMorePath") > 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, 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 Quote: > nor indeed any response at all that I can detect? |
My System Specs![]() |
| | #3 (permalink) |
| | 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. > 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 Specs![]() |
| | #4 (permalink) |
| | 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? 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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. 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. 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 Specs![]() |
![]() |
| 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 | |||