Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Friday 15 September 2023

PowerShell - Special Folders (System Folders)

In VBscript, there existed a concept known as Special Folders, for example, My Documents which could be accessed using the Shell. Application object and passing in a constant that applied to a certain folder. This is also possible using PowerShell.



$a = New-Object -ComObject Shell.Application
Get-ChildItem $a.NameSpace(0x21).Self.Path

The prior two lines of code can also be written as follows: 

Get-ChildItem ((New-Object -ComObject Shell.Application).Namespace(0x21).Self.Path)

Below is the list of special folders and its hex number, please do comment on this post if any of them is/are wrong:

Hex Number Folder Name
0x1 Internet Explorer
0x2 Programs
0x3 Control Panel
0x4 Printers and Faxes
0x5 My Documents
0x6 Favorites
0x7 Startup
0x8 My Recent Documents
0x9 SendTo
0xa Recycle Bin
0xb Start Menu
0xd My Music
0xe My Videos
0x10 Desktop
0x11 My Computer
0x12 My Network Places
0x13 NetHood
0x14 Fonts
0x15 Templates
0x16 All Users Start Menu
0x17 All Users Programs
0x18 All Users Startup
0x18 All Users Startup
0x19 All Users Desktop
0x1a Application Data
0x1b PrintHood
0x1c Local Settings Application Data
0x20 Local Settings Temporary Internet Files
0x21 Cookies
0x22 Local Settings History
0x23 All Users Application Data
0x24 Windows
0x25 System32
0x26 Program Files
0x27 My Pictures
0x28 User Profile
0x2b Common Files
0x2e All Users Templates
0x2f Administrative Tools
0x31 Network Connections


You can also use the .NET way in PowerShell: 

[System.Environment]::GetFolderPath("<SpecialFolder>")
  • Desktop
  • Programs
  • Personal
  • MyDocuments
  • Favorites
  • Startup
  • Recent
  • SendTo
  • StartMenu
  • MyMusic
  • DesktopDirectory
  • MyComputer
  • Templates
  • ApplicationData
  • LocalApplicationData
  • InternetCache
  • Cookies
  • History
  • CommonApplicationData
  • System
  • ProgramFiles
  • MyPictures
  • CommonProgramFiles

Between the following are the possible Enumeration values and their associated numeric values, the VBScript version appears to have more alternatives than the .NET version:
  •  0  Desktop 
  •  2  Programs 
  •  5  Personal 
  •  6  Favourites 
  •  7  Startup 
  •  8  Recent 
  •  9  SendTo 
  •  11 StartMenu 
  •  13 MyMusic 
  •  16 DesktopDirectory 
  •  17 MyComputer 
  •  21 Templates 
  •  26 ApplicationData 
  •  28 LocalApplicationData 
  •  32 InternetCache 
  •  33 Cookies 
  •  34 History 
  •  35 CommonApplicationData 
  •  37 System 
  •  38 ProgramFiles 
  •  39 MyPictures 
  •  43 CommonProgramFiles

FREE Cybersecurity Certifications

Here's 15 FREE courses provided by the Qualys. The cybersecurity firm Qualys focuses on providing cloud-based security and compliance so...