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("Wscript.shell")
   $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
   next

   $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("wscript.shell")

   $MyShortcut = $oShell.CreateShortcut($scNameAndPath)

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

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

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

   $MyShortcut.Save

EndFunction

0 Comments

Submit a Comment

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

You May Also Like…

How to Research a CPU Upgrade

How to Research a CPU Upgrade

Upgrade Time! Doing a lot of VMWare Workstation virtualization to create labs for self-study and training. Finding...