Finding special folders

Windows has a number of special folders. These can be accessed either directly through the file system – for example the Documents special folder is C:\<user>\Richard\Documents or through code. But how do you go about finding special folders.

The easiest way is to use this script

1..1000 |
ForEach-Object {
   $shell = New-Object -ComObject Shell.Application
   $sf = $shell.NameSpace($psitem)

  if ($sf) {
    
     $props = [ordered]@{
       Value = $psitem
       Name = $sf.Title
       Path = $sf.Self.Path
     }

    New-Object -TypeName PSobject -Property $props
   }
}

Looping through the values 1-1000 the Shell.Application COM object is used to find the namespace corresponding to that number. If it exists, the value, name and path are output.

In the Path property you’ll either get a normal looking path e.g. C:\Windows\System32 or something like this – ::{645FF040-5081-101B-9F08-00AA002F954E}   – which is the CLSID or Windows Class Identifier

Advertisements
This entry was posted in COM, Powershell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s