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

   $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

   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…

Meraki Open Source Licenses

Until today I assumed that Meraki was built in-house with only closed source software. But having a look at the...


If you have Veeam backup failing with the Updating BCD failed with Cannot update SafeBoot flag and SentinelOne is...