Returning Shell Folders Using Wscript.Shell and Kix

User profiles have moved between…

Login

Blog History

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 *

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.