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 *

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…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...