[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Best way of opening Explorer to a folder?

Tony Toews

10/3/2010 3:54:00 AM

Folks

As a follow up to my previous posting what's the best way of opening
Windows Explorer to a specific folder.

I've been using the aforementioned API calls to fetch the Windows
folder, concatentae with "explorer" and then add a space and the
folder name. Then execute the string with Shell.

Tony


--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
Tony's Microsoft Access Blog - http://msmvps.com/blo...
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeup...
15 Answers

Kevin Provance

10/3/2010 4:55:00 AM

0


"Tony Toews" <ttoews@telusplanet.net> wrote in message
news:aevfa6h5jhvf0taf1g7jtipthtrggnpatd@4ax.com...
: Folks
:
: As a follow up to my previous posting what's the best way of opening
: Windows Explorer to a specific folder.
:
: I've been using the aforementioned API calls to fetch the Windows
: folder, concatentae with "explorer" and then add a space and the
: folder name. Then execute the string with Shell.
:

Shell out to explorer.exe, "<path to folder to open>"

Keep the quotes, lose everything else and replace it with the path to the
folder to open.

Mayayana

10/3/2010 2:04:00 PM

0

Here's an interesting demo. Create a button,
and a reference to

Microsoft Shell and Automation
(shdoc401.dll pre-XP, shells32 in XP)

and Microsoft Internet Controls
(shdocvw.dll)

Then add this code:

Dim SH As Shell32.Shell

Private Sub Command1_Click()
Dim IE As InternetExplorer
Dim Wins As ShellWindows
Dim Doc As ShellFolderView
Dim Fol As Shell32.Folder, FolItem As Shell32.FolderItem
Dim sLoc As String
Dim i As Long, Pt1 As Long

Set SH = New Shell32.Shell
SH.Open "C:\Windows"
'SH.Explore "C:\Windows\System32" ' opens with treeview.
Set Wins = SH.Windows
For i = 0 To Wins.Count - 1
Set IE = Wins.Item(i)
sLoc = IE.LocationURL
sLoc = Replace(sLoc, "/", "\")
Pt1 = InStr(sLoc, "\\\")
If Pt1 <> 0 Then sLoc = Right$(sLoc, (Len(sLoc) - (Pt1 + 2)))
Debug.Print sLoc
If sLoc = "C:\Windows" Then
IE.Left = 0
IE.Top = 0
End If
Set Doc = IE.Document
Set Fol = Doc.Folder
Set FolItem = Fol.Items.Item(2)
Debug.Print FolItem.Name
Doc.SelectItem FolItem, 1
Next
Set FolItem = Nothing
Set Fol = Nothing
Set Doc = Nothing
Set IE = Nothing
Set SH = Nothing
End Sub

The Shell object is a COM object that provides
access to most Explorer functionality. It's basically
the GUI interface -- roughly equivalent to the
various IShell* interfaces that C++ people use,
but a lot easier to access.

But there are some caveats, as you can see when
you try this code. Microsoft created the Shell* with
Active Desktop. At the time they were fighting a
court case with Netscape and were pretending that
Explorer was the same as IE. Pre-XP, a folder window
actually does have an IE browser window in it, but
it's wrapped by a ShellFolderView object. Shell.Windows
represents all open folders *and* IE instances. Each
is an IE instance, officially, but only in name. Some
IE properties/methods work, others do not work or
are not active. It's a fake IE. But as it turns out, the
IE.Document object is the ShellFolderView for the
folder (if the Windows.Item is a folder and not an IE
instance)! Once you have a ShellFolderView you have a lot
of control over the folder.

Notice that IE.Left and IE.Top don't work. They used
to work on Win9x. Security. And the IE.LocationURL returns
a browser-ized file path that has to be fixed. I think
the long and the short of it is that Microsoft did something
very silly when they created Active Desktop, and forever
since they've had to maintain compatibility. (Remember
when the brilliant Bill Gates had one of his brilliant
insights, realized that the future of computing was
Disney ads on the Desktop, with folders that look like
browser windows, and "turned the Microsoft corporate
ship on a dime" just in time? What a guy.)

Once you get a ShellFolderView you can enumerate
files, select files, etc. But it should be used in a GUI
context. It represents the view, not the file system.
(Ex,: On Win98 the shell folder FolderItems does not
include system files. On XP it does not include hidden
files.)


|
| As a follow up to my previous posting what's the best way of opening
| Windows Explorer to a specific folder.
|
| I've been using the aforementioned API calls to fetch the Windows
| folder, concatentae with "explorer" and then add a space and the
| folder name. Then execute the string with Shell.
|
| Tony
|
|
| --
| Tony Toews, Microsoft Access MVP
| Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
| Tony's Microsoft Access Blog - http://msmvps.com/blo...
| For a convenient utility to keep your users FEs and other files
| updated see http://www.autofeup...


Mayayana

10/3/2010 2:29:00 PM

0

An addendum to that last....
While you can't set IE.Left, IE.Top, you
can return them.

Private Sub Command1_Click()
Dim IE As InternetExplorer
Dim Wins As ShellWindows
Dim i As Long

Set SH = New Shell32.Shell
Set Wins = SH.Windows
For i = 0 To Wins.Count - 1
Set IE = Wins.Item(i)
Debug.Print IE.Left
Debug.Print IE.Top
Next
Set IE = Nothing
Set SH = Nothing
End Sub

With 3 folders open, 1 minimized, I get
this:

688
183
-32000
-32000
529
178

So you can identify a minimzied folder by
looking for an invalid Left or Top.

I think that's a good example of how the
Shell object works. It's poorly designed, with
a convoluted object model. (There are at least 4
ways to look at a folder: IE, ShellFolderView,
Shell Folder object, and Shell Folder FolderItem.
Each provides different access; each is relating
to a visual GUI entity; yet none of them has a
simple boolean Minimized property.)

Nevertheless, Shell also lends itself to all sorts
of fun hacks and provides a lot of access that's
not available "elsewise".



tmoran4511

10/3/2010 3:35:00 PM

0

On Oct 2, 8:54 pm, Tony Toews <tto...@telusplanet.net> wrote:
> Folks
>
> As a follow up to my previous posting what's the best way of opening
> Windows Explorer to a specific folder.
>
> I've been using the aforementioned API calls to fetch the Windows
> folder, concatentae with "explorer" and then add a space and the
> folder name.  Then execute the string with Shell.
>
> Tony
>
> --
> Tony Toews, Microsoft Access MVP
> Tony's Main MS Access pages -http://www.granite.ab.ca/ac...
> Tony's Microsoft Access Blog -http://msmvps.com/blo...
> For a convenient utility to keep your users FEs and other files
>   updated seehttp://www.autofeup...

Hi Tony:

The simplest methods are Shell or ShellExecute.

With Shell you can really only pass the folder name. If you pass a
specific filename it will attempt to display or run that file.

With ShellExecute you can pass the folder and have it select a
specific filename without attempting to run it.

The ShellExecute Syntax is:

Call ShellExecute(0&, vbNullString, "explorer.exe", "/select," &
FileName, vbNullString, vbNormalFocus)


Tom

Tony Toews

10/3/2010 7:24:00 PM

0

On Sun, 3 Oct 2010 00:55:18 -0400, "Kevin Provance" <k@p.c> wrote:

>Shell out to explorer.exe, "<path to folder to open>"

Yup, that's working just fine.

>Keep the quotes, lose everything else and replace it with the path to the
>folder to open.

Actually you don't need the quotes when using inside a program. When
calling from the command prompt or a bat/cmd file then you do need the
double quotes.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
Tony's Microsoft Access Blog - http://msmvps.com/blo...
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeup...

Kevin Provance

10/3/2010 10:22:00 PM

0

You need the quotes when not using the 8.3 format.


"Tony Toews" <ttoews@telusplanet.net> wrote in message
news:e0mha65m005b2sael03k1cn91tv384pr90@4ax.com...
: On Sun, 3 Oct 2010 00:55:18 -0400, "Kevin Provance" <k@p.c> wrote:
:
: >Shell out to explorer.exe, "<path to folder to open>"
:
: Yup, that's working just fine.
:
: >Keep the quotes, lose everything else and replace it with the path to the
: >folder to open.
:
: Actually you don't need the quotes when using inside a program. When
: calling from the command prompt or a bat/cmd file then you do need the
: double quotes.
:
: Tony
: --
: Tony Toews, Microsoft Access MVP
: Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
: Tony's Microsoft Access Blog - http://msmvps.com/blo...
: For a convenient utility to keep your users FEs and other files
: updated see http://www.autofeup...

Tony Toews

10/4/2010 6:23:00 AM

0

On Sun, 3 Oct 2010 18:22:22 -0400, "Kevin Provance" <k@p.c> wrote:

No, you don't need the double quotes when doing a shell. I just
double checked.

Tony

>You need the quotes when not using the 8.3 format.
>
>
>"Tony Toews" <ttoews@telusplanet.net> wrote in message
>news:e0mha65m005b2sael03k1cn91tv384pr90@4ax.com...
>: On Sun, 3 Oct 2010 00:55:18 -0400, "Kevin Provance" <k@p.c> wrote:
>:
>: >Shell out to explorer.exe, "<path to folder to open>"
>:
>: Yup, that's working just fine.
>:
>: >Keep the quotes, lose everything else and replace it with the path to the
>: >folder to open.
>:
>: Actually you don't need the quotes when using inside a program. When
>: calling from the command prompt or a bat/cmd file then you do need the
>: double quotes.
>:
>: Tony
>: --
>: Tony Toews, Microsoft Access MVP
>: Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
>: Tony's Microsoft Access Blog - http://msmvps.com/blo...
>: For a convenient utility to keep your users FEs and other files
>: updated see http://www.autofeup...

--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
Tony's Microsoft Access Blog - http://msmvps.com/blo...
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeup...

Larry Serflaten

10/4/2010 12:18:00 PM

0


"Tony Toews" <ttoews@telusplanet.net> wrote
>
> As a follow up to my previous posting what's the best way of opening
> Windows Explorer to a specific folder.
>
> I've been using the aforementioned API calls to fetch the Windows
> folder, concatentae with "explorer" and then add a space and the
> folder name. Then execute the string with Shell.


Since Rick Rothstein isn't around, I'll have to fill in for him....

CreateObject("Shell.Application").Open "C:\Program Files\"

<g>
LFS


Mayayana

10/4/2010 1:20:00 PM

0

|
| CreateObject("Shell.Application").Open "C:\Program Files\"
|

That's the Shell object I posted about above.
Same thing. There's no need to use it late-bound.


Jeff Johnson [MVP: VB]

10/4/2010 2:51:00 PM

0

"Tony Toews" <ttoews@telusplanet.net> wrote in message
news:aevfa6h5jhvf0taf1g7jtipthtrggnpatd@4ax.com...

> As a follow up to my previous posting what's the best way of opening
> Windows Explorer to a specific folder.

Here's an old KB article: http://support.microsoft.com...