Windows Special Folders

By FiberOPtics on Jan 04, 2006

Author: FiberOPtics -- mirc.fiberoptics@gmail.com




Usage: $specialfolder(folder) or /specialfolder folder




Purpose:




Returns the path of a Windows Special Folder. This has the same functionality as nLINKn's specdir function, however with the use of COM instead of with a DLL.




Categories:




AllUsersAppdata


AllUsersDesktop


AllUsersFavorites


AllUsersPrograms


AllUsersStartMenu


AllUsersStartup


Appdata


Comspec


Cookies


Desktop


Favorites


Fonts


History


Internetcache


LocalAppdata


MyDocuments


MyPictures


Nethood


Printhood


ProgramFiles


Programs


Recent


Sendto


StartMenu


Startup


System


Templates


Userprofile


Windir




Requirements:




17 out of 29 categories are retrieved with Wscript.Shell's SpecialFolder property which will work on any OS tarting from Windows 98.




4 out of the remaining 12 are retrieved with Wscript.Shell's ExpandEnvironmentStrings method which will work on any OS starting from Windows 98.




The remaining 8 are retrieved with VBscript and the MSScriptControl object to interpret VBscript/Jscript, which will work on any OS starting from Windows ME.




These 8 special folders are:




AllUsersAppdata, AllUsersFavorites, Cookies, History, Internetcache, LocalAppdata, MyPictures, System




mIRC 5.9




Notes:




The main reason for releasing the snippets is for showing different techniques using COM, so primarily for educational purposes.




Some possible usages:



  • Use $asctime($file($specialfolder(windir)).ctime) to return the Windows Install date.



  • Get path of temporary internet files to import caches from IE for a scripted browser.


  • Write/read from your "My Documents" folder from within mIRC on any system.


  • Use it along with a /shortcut snippet to create Windows shorcuts (.lnk & .url), so that you can write a shortcut to the Start/Menu/Desktop/Startup/Sendto/Favorites/...


  • Read/write from/to your IE's Favorites folder.


  • Get the path of the Fonts folder to check the available fonts.


  • Use the code for educational purposes, being the usage of COM, and the way VBScript can be interpreted in mIRC.


  • ...




    I'm aware Comspec isn't a special folder, but I added it anyway. It returns the full path to the command line, for example C:\WINDOWS\system32\cmd.exe




    Examples:




    $specialfolder(windir)


    /specialfolder userprofile
alias specialfolder {
  var %e = !echo $color(info) -a Specialfolder:
  if ($1 == $null) { %e Insufficient parameters. | return }
  var %f1 = $&
    AllUsersDesktop AllUsersStartMenu AllUsersPrograms AllUsersStartup $&
    Desktop AppData PrintHood Templates Fonts NetHood . $&
    StartMenu SendTo Recent Startup Favorites MyDocuments Programs
  var %f2 = $&
    LocalAppdata . . AllUsersFavorites Internetcache Cookies $&
    History AllUsersAppdata . System . MyPictures
  var %f3 = Windir Programfiles Userprofile Comspec
  if ($1 == .) || (!$istok(%f1 %f2 %f3,$1,32)) {
    %e incorrect special folder - Possible:
    tokenize 32 $sorttok($remove(%f1 %f2,.) %f3,32)
    echo -a $*
    return
  }
  var %result = COM Error
  if ($istok(%f1 %f3,$1,32)) {
    var %objWSH = a $+ $ticks
    .comopen %objWSH wscript.shell
    if (!$comerr) {
      if ($findtok(%f1,$1,1,32)) %result = $com(%objWSH,SpecialFolders,3,uint,$calc($ifmatch - 1))
      else %result = $com(%objWSH,ExpandEnvironmentStrings,3,bstr*,% $+ $1%)
      %result = $com(%objWSH).result
      .comclose %objWSH
    }
  }
  else {
    if ($istok(95 98,$os,32)) { %e need atleast Windows ME to retrieve this path | return }
    var %objScript = a $+ $ticks
    .comopen %objScript msscriptcontrol.scriptcontrol
    if (!$comerr) {
      %result = $com(%objScript,language,4,bstr*,vbscript)
      %result = createobject("shell.application").namespace( $&
        $calc($findtok(%f2,$1,1,32) + 27) ).self.path
      %result = $com(%objScript,eval,1,bstr*,%result)
      %result = $com(%objScript).result
      .comclose %objScript
    }
  }
  $iif($isid,return,echo -a) %result
}

Comments

Sign in to comment.
RoninWarrior   -  Jan 04, 2006

i have something similar but not as detailed this deffintly works so much simpliar then mine awsome jon fiber.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.