Returning Shell Folders Using Wscript.Shell and Kix

Written by James McDonald

March 31, 2011

User profiles have moved between Windows XP and Vista/Windows 7 so to create portable logon scripts you need to be able to resolve the correct locations of a users Desktop, Favourites etc.

Using Wscript.Shell’s SpecialFolders property you can return the correct path to your Kix script. If the SpecialFolders property doesn’t exist on the OS you will get an empty string.

   $oshell = CreateObject("")
   $strDesktop = $oShell.SpecialFolders("Desktop")
   ? "My Desktop"
   ? $strDesktop
    $special_folders = "AllUsersDesktop", "AllUsersStartMenu", "AllUsersPrograms", "AllUsersStartup", "Desktop", "Favorites", "Fonts", "MyDocuments", "NetHood" , "PrintHood" , "Programs" , "Recent" ,"SendTo" , "StartMenu", "Startup" ,"Templates"

    for each $item in $special_folders
      $is_it_there = $oShell.SpecialFolders($item)
      ? $item + " : " +  $is_it_there

   $Server = "myserver"
   $pallet_trace_url = "http://" + $Server + "/mywebs/pallet-trace/pallet-trace-live.html"
   $scName = "Pallet Trace.url"
   CreateShortcut ( $strDesktop + "/" + $scName , $pallet_trace_url, "", "","")

Function CreateShortcut($scNameAndPath, $scTarget, $scWorkingDir, $scArgs, $scIconLocation)

   $oShell = CreateObject("")

   $MyShortcut = $oShell.CreateShortcut($scNameAndPath)

   ; Set shortcut object properties and save it
   $MyShortcut.TargetPath = $scTarget

   If NOT $scIconLocation = ""
      $MyShortCut.IconLocation = $scIconLocation

   If NOT $scWorkingDir = ""
      $MyShortcut.WorkingDirectory = $scWorkingDir
   If NOT $scArgs = ""
      $MyShortcut.Arguments = $scArgs




Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…