jcunews

ListSpecialFolders.vbs

Aug 8th, 2019 (edited)
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'This script will discover available special folders in the current system and
  2. 'display their name and path. It will also list some known Windows version
  3. 'specific special folders which are available but are not yet made accessible
  4. 'in a system.
  5. '
  6. 'GUID paths such as "::{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" can be opened
  7. 'similar to file paths via Run dialog, EXPLORER.EXE argument, or the START
  8. 'command argument of the command prompt.
  9. '
  10. 'File path based special folders have special folder view when opened using
  11. 'Explorer.
  12. '
  13. 'Other special folders which have path such as
  14. '"FolderName.{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" can be opened after
  15. 'creating a folder with any name followed by a period then followed by a GUID.
  16. 'Some of these known special folders are only available on specific Windows
  17. 'version.
  18. '
  19. 'https://www.reddit.com/user/jcunews1/
  20.  
  21. function extractname(p)
  22.   dim i
  23.   i = instrrev(p, "\")
  24.   if i > 0 then
  25.     extractname = mid(p, i + 1)
  26.   else
  27.     extractname = p
  28.   end if
  29. end function
  30.  
  31. function issub(fi)
  32.   dim n
  33.   n = extractname(fi.path)
  34.   issub = fi.isfolder and (left(fi.path, 2) = "::") and _
  35.     ((left(n, 2) = "::") or isnumeric(n))
  36. end function
  37.  
  38. sub explore(fd, lv)
  39.   dim fi, s
  40.   set fi = fd.self
  41.   if issub(fi) or ((fi.name = "Desktop") and (fi.type = "")) then
  42.     if lv > 0 then
  43.       s = extractname(fi.path)
  44.       if left(s, 2) = "::" then
  45.         redim preserve clsids(ubound(clsids) + 1)
  46.         clsids(ubound(clsids)) = mid(s, 3)
  47.       end if
  48.     end if
  49.     for each fi2 in fd.items
  50.       if issub(fi2) then
  51.         cnt = cnt + 1
  52.         wscript.echo string(lv, " ") & """" & fi2.name & """ " & fi2.path
  53.         explore fi2.getfolder, lv + 2
  54.       end if
  55.     next
  56.   end if
  57. end sub
  58.  
  59. dim clsids()
  60. redim clsids(-1)
  61.  
  62. wscript.echo "[Desktop]"
  63. set sa = createobject("shell.application")
  64. cnt = 0
  65. explore sa.namespace(0), 0
  66. wscript.echo vbcrlf & "Total: " & cnt
  67.  
  68. wscript.echo vbcrlf & "[Global]"
  69. dim unusables(9)
  70. unusables(0) = "{04731B67-D933-450A-90E6-4ACD2E9408FE}" 'search result
  71. unusables(1) = "{64693913-1C21-4F30-A98F-4E52906D3B56}" '?app instance?
  72. unusables(2) = "{89D83576-6BD1-4C86-9454-BEB04E94C819}" 'office outlook
  73. unusables(3) = "{8FD8B88D-30E1-4F25-AC2B-553D3D65F0EA}" 'external devices
  74. unusables(4) = "{98F275B4-4FFF-11E0-89E2-7B86DFD72085}" 'startmenu launcher provider
  75. unusables(5) = "{A00EE528-EBD9-48B8-944A-8942113D46AC}" 'startmenu commanding provider
  76. unusables(6) = "{BD7A2E7B-21CB-41B2-A086-B309680C6B7E}" 'offline files
  77. unusables(7) = "{DAF95313-E44D-46AF-BE1B-CBACEA2C3065}" 'startmenu provider
  78. unusables(8) = "{E345F35F-9397-435C-8F95-4E922C26259E}" 'startmenu path complete provider
  79. unusables(9) = "{EDC978D6-4D53-4B2F-A265-5805674BE568}" 'stream backed folder
  80. dim names(0)
  81. names(0) = split("{450D8FBA-AD25-11D0-98A8-0800361B1103}|My Documents", "|")
  82. set ws = createobject("wscript.shell")
  83. HKCR = &h80000000
  84. set reg = getobject("winmgmts:{impersonationlevel=impersonate}!\\.\root\default:stdregprov")
  85. reg.enumkey HKCR, "CLSID", keys
  86. cnt = 0
  87. on error resume next
  88. for each key in keys
  89.   key = ucase(key)
  90.   for i = 0 to ubound(unusables)
  91.     if unusables(i) = key then
  92.       key = ""
  93.       exit for
  94.     end if
  95.   next
  96.   if (key <> "") and ((reg.getdwordvalue(HKCR, "CLSID\" & key & "\ShellFolder", "Attributes", val) = 0) or (reg.getbinaryvalue(HKCR, "CLSID\" & key & "\ShellFolder", "Attributes", val) = 0)) then
  97.     reg.getstringvalue HKCR, "CLSID\" & key, "", val
  98.     if vartype(val) <> vbstring then val = ""
  99.     set fd = nothing
  100.     set fd = sa.namespace("::" & key)
  101.     if not (fd is nothing) then
  102.       for i = 0 to ubound(clsids)
  103.         if clsids(i) = key then
  104.           key = ""
  105.           exit for
  106.         end if
  107.       next
  108.       if key <> "" then
  109.         cnt = cnt + 1
  110.         if val <> "" then
  111.           val = """" & val & """"
  112.         else
  113.           val = """"""
  114.           for i = 0 to ubound(names)
  115.             if names(i)(0) = key then
  116.               val = "<" & names(i)(1) & ">"
  117.               exit for
  118.             end if
  119.           next
  120.         end if
  121.         wscript.echo val & " ::" & key
  122.       end if
  123.     end if
  124.   end if
  125. next
  126. on error goto 0
  127. wscript.echo vbcrlf & "Total: " & cnt
  128.  
  129. wscript.echo vbcrlf & "[File System]"
  130. set fs = createobject("scripting.filesystemobject")
  131. cnt = 0
  132. for i = 0 to &H5F
  133.   set fd = sa.namespace(i)
  134.   if not (fd is nothing) then
  135.     set fi = fd.self
  136.     p = fi.path
  137.     if left(p, 2) = "::" then p = ""
  138.     if (p <> "") and fs.fileexists(p & "\desktop.ini") then
  139.       set f = fs.opentextfile(p & "\desktop.ini", 1)
  140.       h = false
  141.       do while not f.atendofstream
  142.         s = trim(f.readline)
  143.         if s = "[.ShellClassInfo]" then
  144.           h = true
  145.         elseif s <> "" then
  146.           s = split(s, "=")
  147.           if (ubound(s) = 1) and (right(ucase(s(0)), 5) = "CLSID") and h then
  148.             p = ""
  149.             exit do
  150.           end if
  151.         end if
  152.       loop
  153.       f.close
  154.       if p = "" then
  155.         cnt = cnt + 1
  156.         wscript.echo """" & fi.name &""" "& fi.path
  157.       end if
  158.     end if
  159.   end if
  160. next
  161. wscript.echo "<.NET Assembly> C:\Windows\assembly"
  162. wscript.echo vbcrlf & "Total: " & cnt + 1
  163.  
  164. wscript.echo vbcrlf & "[Known Other Special Folders]"
  165. wscript.echo "<Win2K/XP/2K3 ActiveX Cache> FolderName.{88C6C381-2E85-11D0-94DE-444553540000}"
  166. wscript.echo "<Win2K/XP/2K3 Internet Explorer History> FolderName.{FF393560-C2A7-11CF-BFF4-444553540000}"
  167. wscript.echo "<Vista+ Control Panel (all)> FolderName.{ED7BA470-8E54-465E-825C-99712043E01C}"
  168. wscript.echo "<Vista+ Recent Folders> FolderName.{22877a6d-37a1-461a-91b0-dbda5aaebc99}"
  169. wscript.echo vbcrlf & "Total: 4"
Add Comment
Please, Sign In to add comment