Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Special Folder Shell Namespace number vs title

688 views
Skip to first unread message

Paul Randall

unread,
Feb 29, 2008, 12:55:28 AM2/29/08
to
I can obtain a Shell Application Folder object associated with a
Windows Special Folder with code like the following:
iNameSpace = 26
Set oShApp = CreateObject("Shell.Application")
Set oShFolder = oShApp.NameSpace(iNameSpace)
MsgBox oShFolder.Title

On my WXP SP2 system, for numbers in the range 0 to 61, most numbers
result in a shell folder object with a unique title. My system has 39
unique titles.

Some titles, like 'Application Data', and 'Desktop', are associated
with namespaces of more than one number. For example, 26, 28, and 35
all result in shell folders with the title 'Application Data'.

Question: Are all the shell folders with the same title identical,
having the same properties, methods, events, etc, as well as the same
contents? If not, how can I find out the differences between them?

Thanks,

-Paul Randall

Here is a short script to list the special folder namespace titles and
the numbers associated with them:

Set dNameSpaces = GetNameSpaces()

sMsg = ""
For Each sNameSpace In SortNet(dNameSpaces.Keys)
sMsg = sMsg & sNameSpace & vbTab & vbTab & _
dNameSpaces(sNameSpace) & vbCrLf
Next 'sNameSpace
MsgBox "Namespace Title count = " & UBound(dNameSpaces.Keys) + 1 & _
vbCrLf & sMsg

Function GetNameSpaces()
'Return a dictionary containing namespace titles and associated
numbers.
Dim dNameSpaces, dNameSpaces2, oShApp, oShFolder, sNameSpace
Set dNameSpaces = CreateObject("scripting.dictionary")
dNameSpaces.comparemode = vbTextCompare
Set dNameSpaces2 = CreateObject("scripting.dictionary")
dNameSpaces2.comparemode = vbTextCompare
Set oShApp = CreateObject("Shell.Application")

On Error Resume Next
For i = 0 To 100
Set oShFolder = oShApp.NameSpace(i)
dNameSpaces(oShFolder.Title) = dNameSpaces(oShFolder.Title) & i & " "
Next 'i
On Error Goto 0
For Each sNameSpace In SortNet(dNameSpaces.Keys)
dNameSpaces2(sNameSpace) = Replace(Trim(dNameSpaces(sNameSpace))," ",
",")
Next 'sNameSpace
Set GetNameSpaces = dNameSpaces2
End Function 'GetNameSpaces

Function SortNet(a1DArray)
Dim i
With CreateObject ("System.Collections.ArrayList")
For i = 0 To UBound(a1DArray)
.Add a1DArray(i)
Next
.Sort()
SortNet = .ToArray
End With
End Function


mayayana

unread,
Feb 29, 2008, 9:59:02 AM2/29/08
to
>
> Question: Are all the shell folders with the same title identical,
> having the same properties, methods, events, etc, as well as the same
> contents? If not, how can I find out the differences between them?
>
You might want to check the path instead of
the name. There's a current user App Data folder
and an All Users App Data folder.

I've got this list I made up at one point. I'm
not certain it's up to date. I know it's not up
to date for Vista, but I think it is for XP. I marked
A or U to signify all users or current user:

U - Desktop 0
U - Start Menu\Programs 2
U - Personal 5
U - Favorites 6
U - Start Menu\Programs\Startup 7
U - Recent 8
U - SendTo 9
Recycle Bin 10
U - Start Menu 11
Fonts 20
U - ShellNew 21
A - Start Menu 22
A - Start Menu\Programs 23
A - Start Menu\Programs\Startup 24
All users\Desktop 25
U - Application Data 26
U - IECache 32
Cookies 33
History 34
A - Application Data 35
Windows 36
System 37
Program Files 38
A - ShellNew 45
A - documents 46
U - start menu\programs\Admin. tools 47
A - start menu\programs\Admin. tools 48


Paul Randall

unread,
Feb 29, 2008, 11:53:57 AM2/29/08
to

"mayayana" <mayaXX...@mindXXspring.com> wrote in message
news:%23ztytOu...@TK2MSFTNGP04.phx.gbl...

Thanks. I will play with it.

I have a related question:
The filter method, with wildcards, can be used to get a subset of
items. I can't find anything in the documentation about what field is
filtered, or whether the filter field can be specified. For the
Temporary Internet Files special folder, the filter works on the URL
field, which leads me to believe that each special folder may use a
different field to filter on. Do you have a document or quick and
dirty way to determine the filter field for each special folder type?

-Paul Randall


mayayana

unread,
Feb 29, 2008, 5:53:46 PM2/29/08
to
Sorry, but I have no idea what you're talking
about. :) Filter field? I've never used the Filter
function, if that's what you mean, but in looking
at the docs it just seems to be a compact version
of doing InStr on all members of an array.

Alexander Mueller

unread,
Feb 29, 2008, 6:49:27 PM2/29/08
to
Paul Randall schrieb:

> I have a related question:
> The filter method, with wildcards, can be used to get a subset of
> items. I can't find anything in the documentation about what field is
> filtered, or whether the filter field can be specified. For the
> Temporary Internet Files special folder, the filter works on the URL
> field, which leads me to believe that each special folder may use a
> different field to filter on. Do you have a document or quick and
> dirty way to determine the filter field for each special folder type?


The Filter method applies to a FolderItems collection (FolderItems3
interface), rather then to the Folder-object itself.
It's primarily designed to filter file names using wildcards, as in
DOS and the DIR command or the Windows file search dialog.

As for Shell folders andf their items that don't represent file system
structures or do represent them in a specially modified way (as
TIF/Cookies), I *think* 'Filter' works on the value of the Item's
Name property, simply because that what it does for the FS items too.

How did you get the 'Filter' method working for TIF-Items?
Filter doesn't seem to filter anything for the IE cache on
my system (XP). Neither the Flags nor the filter string seems to
have any effect. Maybe i missed something.


The issue is btw somewhat related to the GetDetailsOf method and its
"columns" which actually differ between different Shell folders in
number, name and values.
Try the script below, to see which folder has which subset of
columns/fields. Most likely the Filter method always applies to the
first column : Name


MfG
Alex


'check the names of the fileds returned by GetDetailsOF
'for different shell special folders

Set sh = CreateObject("Shell.Application")

'Iterate SSFs by numeric index


For i = 0 To 100

Set f = sh.Namespace (i)
If Not f Is Nothing Then

columns = ""
'Iterate possible columns by numeric index
For j = -10 To 100
detail = f.GetDetailsOf (Empty, j)
If Len(detail) > 0 Then
columns = columns & j & " " _
& detail & vbCrLf
End If
Next

folder = "SSF: " & i & vbcrlf & "Title: " & f.Title
path = f.Self.Path

If Len(path) Then
folder = folder & vbcrlf & "Path: " & path
End If

If Len(columns) = 0 Then
columns = "(No columns defined)"
End If

all = folder & vbcrlf & vbcrlf _
& "Columns:" & vbcrlf & columns

If vbCancel = MsgBox (all, vbOkCancel) Then
WSH.Quit
End If

End If
Next

MfG,
Alex

Paul Randall

unread,
Mar 1, 2008, 11:56:18 AM3/1/08
to

"Alexander Mueller" <mill...@hotmail.com> wrote in message
news:47c89a06$0$21942$9b4e...@newsspool2.arcor-online.net...

Thanks for the input.
If I navigate to msdn.microsoft.com, then run the following script, it
shows this message:
Count before filter = 239
Count after filter = 3

I think this shows that the filter is working on the internet address
field (1) and not the name field (0). Perhaps 'field' is the wrong
term to use here. In a window, the Temporary Internet Files folder
can display the following fields:
Expires,4
Internet Address,1
Last Accessed,6
Last Checked,7
Last Modified,5
Name,0
Size,3
Type,2


Const ShContF_Folders = 32
Const ShContF_NonFolders = 64
Const ShContF_IncludeHidden = 128
Const ShContF_Init_On_First_Next = 256
Const ShContF_NetPrinterSrch = 512
Const ShContF_Shareable = 1024
Const ShContF_Storage = 2048
dim objShell
set objShell = CreateObject("Shell.Application")
Dim objFolder
set objFolder = objShell.NameSpace(32)
dim objFolderItems3
set objFolderItems3 = objFolder.Items()
Dim sMsg
sMsg = "Count before filter = " & _
objFolderItems3.Count & vbCrLf
objFolderItems3.Filter ShContF_NonFolders, "*/en-us/*.gif"
sMsg = sMsg & "Count after filter = " & _
objFolderItems3.Count
MsgBox sMsg

-Paul Randall


Alexander Mueller

unread,
Mar 1, 2008, 3:31:58 PM3/1/08
to
Paul Randall schrieb:

...


Hi Paul thanks for your the reply and the input.

You're right, Filter also works on TIF items and probably on
other non-FS items of other special folders, too.

I noticed that one needs to set a reference to the Folder.Items
collection, as you did with

Set objFolderItems3 = objFolder.Items()

and then apply filter on that reference.

objFolderItems3.Filter ..., ...

If the Filter method is run directly from the Items property:

objFolder.Items().Filter ..., ...

it has no impact, nothing's filtered - interesting.

Returning to your first question, it really seems to be undocumented
which field/attribute of an item is used for Filter if it's not a
file system item. So probably Trial and Error is the way to go.


MfG,
Alex

Paul Randall

unread,
Mar 2, 2008, 3:14:15 PM3/2/08
to

"mayayana" <mayaXX...@mindXXspring.com> wrote in message
news:%23ztytOu...@TK2MSFTNGP04.phx.gbl...
> >

Thanks for the info. It took a while to figure out how to find the
path, but in the process I learned that the .Self property of a
Shell.Application folder presents a different interface to the same
folder, an interface that includes a Path property. Now I see that
duplicate titles are generally associated with a namespace pair for
the current user and 'all users'.

I am now down to just a few namespaces that appear to be identical:
Title, NameSpace Number, Path
Desktop,0,C:\Documents and Settings\Paul\Desktop
Desktop,16,C:\Documents and Settings\Paul\Desktop

system32,37,C:\WINDOWS\system32
system32,41,C:\WINDOWS\system32

And I have an oddball Workgroup namespace with a strange path:
Workgroup,61,Workgroup

Here is my script to list the file system path (where available) for
all the namespaces accessible via a namespace number:

Option Explicit
Dim oShApp


Set oShApp = CreateObject("Shell.Application")

Dim i, Temp, sItem, oShFolder
Dim odSpecFldrs
Set odSpecFldrs = CreateObject("scripting.dictionary")
odSpecFldrs.comparemode = vbTextCompare

'Assuming shell namespaces are numbered from 0 to 255,
' create a dictionary containing keys consisting of an
' alphabetic list of namespace titles followed by a comma
' and the namespace number. For example, there may be
' keys like: Desktop,0 and Desktop,16 and Desktop,25.
For i = 0 To 255
Set oShFolder = oShApp.NameSpace(i)
If TypeName(oShFolder) <> "Nothing" Then
odSpecFldrs(i) = oShFolder.Title & "," & i
On Error Resume Next
odSpecFldrs(i) = odSpecFldrs(i) & "," & oShFolder.Self.Path
On Error Goto 0
End If
Next 'i

fOverWrite "SpecFolderPaths.txt", _
Join(SortNet(odSpecFldrs.Items), vbCrLf)
MsgBox "Done - NameSpace Titles, Numbers and File Paths have " &
vbCrLf & _
"been written to file SpecFolderPaths.txt"

Function SortNet(a1DArray)
Dim i
With CreateObject ("System.Collections.ArrayList")
For i = 0 To UBound(a1DArray)
.Add a1DArray(i)
Next
.Sort()
SortNet = .ToArray
End With
End Function

Sub fOverWrite(sFileName, sText)
With CreateObject("Scripting.FileSystemObject")
On Error Resume Next
.CreateTextFile(sFileName, True, False). _
Write(sText)
If Err Then 'Try Unicode file.
On Error GoTo 0
.CreateTextFile(sFileName, True, True). _
Write(Text)
End If
On Error GoTo 0
End With
End Sub

-Paul Randall


Alexander Mueller

unread,
Mar 2, 2008, 7:10:32 PM3/2/08
to
Paul Randall schrieb:

That interface is the (Shell)FolderItem interface.
http://msdn2.microsoft.com/en-us/library/bb787810(VS.85).aspx

The Self property kind of a casts the Folder2 object to
a FolderItem object.
http://msdn2.microsoft.com/en-us/library/bb787860(VS.85).aspx


> Now I see that
> duplicate titles are generally associated with a namespace pair for
> the current user and 'all users'.
>
> I am now down to just a few namespaces that appear to be identical:
> Title, NameSpace Number, Path

> Desktop,0,C:\Documents and Settings\Paul\Desktop
> Desktop,16,C:\Documents and Settings\Paul\Desktop

0 is the ssfDESKTOP constant, while 16 resolves ssfDESKTOPDIR.
While the Path points to the same location, there are some practical
differences between both folders:

The ssfDESKTOP shellfolder includes all items that you can see on your
desktop, e.g. "virtual items" such as "My Computer", "My Documentes"
"Recycle Bin" etc (which are special folders themself) and also the
items physically located in ...\All Users\Desktop.
Also it is the root folder of all folders of the Windows Shell.

The ssfDESKTOPDIRECTORY shellfolder includes only the items physically
located in the current users Desktop directory, so these are usually
less items and all items are FS.

Try:

Set sh = CreateObject("Shell.Application")

WSH.Echo sh.Namespace(0).Items.Count
WSH.Echo sh.Namespace(16).Items.Count


> system32,37,C:\WINDOWS\system32
> system32,41,C:\WINDOWS\system32

The constants names are: ssfSYSTEM vs ssfSYSTEMx86.
Namespace and path are the same on a 32-bit system, but
different on a 64-bit machine.

ffr: "ShellSpecialFolderConstants"
http://msdn2.microsoft.com/en-us/library/bb774096(VS.85).aspx


MfG,
Alex

mayayana

unread,
Mar 2, 2008, 8:53:46 PM3/2/08
to
> odSpecFldrs(i) = odSpecFldrs(i) & "," & oShFolder.Self.Path

I've never been sure whether the Self property
was available since it's a "Folder2" property. I
guess if it works on all systems it's OK. I usually
use the following to be on the safe side:

CPt = InStr(Fol.Title, ":")
If CPt > 0 Then
s = Fol.Title
s = Mid(s, (CPt - 1), 2) & "\"
Else
Set Fol1 = Fol.ParentFolder.ParseName(Fol.Title)
s = Fol1.Path
End If

But actually I think both have limitations.
On my system, if I select the Desktop icon
in BrowseForFolder, both methods return "".
By returning title I get "Desktop". While that
doesn't apply to what you're doing, it's a
"gotcha" with BrowseForFolder. Namespaces
don't work properly.

Personally I try to avoid Shell methods
whenever possible. It's an undependable object,
designed to accomodate folder views rather than
file system functions. In my tests, on Win98,
with all file types visible, enumerating files from
FolderItems doesn't return PE files! (EXE, DLL)
On XP it doesn't return hidden files.

But I guess there's no other option when it comes
to finding all system folder paths.

> With CreateObject ("System.Collections.ArrayList")

That's some fancy footwork. A .Net array? Does
that have advantages over a VBS collection
or array?

Paul Randall

unread,
Mar 2, 2008, 9:16:41 PM3/2/08
to

"Alexander Mueller" <mill...@hotmail.com> wrote in message
news:47cb41f6$0$14414$9b4e...@newsspool3.arcor-online.net...


Thank you, Alex. I appreciate the time you have taken to explain this
to me.

I guess just because it looks like a duck (same title and
item-property list) and quacks like a duck (same path), doesn't mean
it is a duck (different contents).

-Paul Randall


0 new messages