XMetaL Tips and Tricks

XMetaL Community Forum XMetaL Tips and Tricks Script Example: Finding the Paths to Windows "Special Folders"

  • Derek Read

    Script Example: Finding the Paths to Windows "Special Folders"

    Participants 1
    Replies 0
    Last Activity 7 years, 3 months ago

    XMetaL Author, XMetaL Developer

    You may find you need to locate the paths to certain Windows “Special Folders” when writing a script for use with XMetaL Author, such as the current user's “My Documents” folder or the path to their “Desktop”.

    The following JScript example demonstrates how to instantiate the Windows Script Host and use its SpecialFolders object to obtain the various paths it exposes. The script obtains all the values known to date, joins them together as a string and displays that using an XMetaL “MessageBox” dialog.

    This list is not meant to be a complete reference and may have omitted some values. Please refer to Microsoft's documentation for the most up to date information. It is possible that Microsoft will extend or alter these in newer versions of Windows.

    [code]//XMetaL Script Language JScript:
    //Instantiate the WSH COM control's Shell object
    var wsh = new ActiveXObject(“Wscript.Shell”);

    //Build one big string containing a single special folder value per line
    var msg = “”;
    msg += “nAllUsersDesktop:n   ”   + wsh.SpecialFolders.Item(“AllUsersDesktop”);   //Folder that contains shortcuts that appear on the desktop for all users
    msg += “nAllUsersStartMenu:n   ” + wsh.SpecialFolders.Item(“AllUsersStartMenu”); //Folder that contains shortcuts that appear on the Start menu for all users
    msg += “nAllUsersPrograms:n   ”  + wsh.SpecialFolders.Item(“AllUsersPrograms”);  //Folder that contains shortcuts that appear on the Programs menu for all users
    msg += “nAllUsersStartup:n   ”   + wsh.SpecialFolders.Item(“AllUsersStartup”);   //Folder that contains shortcuts to programs that are run on startup for all users
    msg += “nDesktop:n   ”           + wsh.SpecialFolders.Item(“Desktop”);           //Folder that contains shortcuts that appear on the desktop for the current user
    msg += “nFavorites:n   ”         + wsh.SpecialFolders.Item(“Favorites”);         //Folder that contains shortcuts saved as favorites by the current user
    msg += “nFonts:n   ”             + wsh.SpecialFolders.Item(“Fonts”);             //Folder that contains fonts installed on the system
    msg += “nMyDocuments:n   ”       + wsh.SpecialFolders.Item(“MyDocuments”);       //Folder that contains current user's documents
    msg += “nNetHood:n   ”           + wsh.SpecialFolders.Item(“NetHood”);           //Folder that contains objects that appear in Network Neighborhood
    msg += “nPrintHood:n   ”         + wsh.SpecialFolders.Item(“PrintHood”);         //Folder that contains printer links
    msg += “nRecent:n   ”            + wsh.SpecialFolders.Item(“Recent”);            //Folder that contains shortcuts to current users recently opened documents
    msg += “nSendTo:n   ”            + wsh.SpecialFolders.Item(“SendTo”);            //Folder that contains shortcuts to applications that show up as possible send-to targets when a user right-clicks on a file in Windows Explorer
    msg += “nStartMenu:n   ”         + wsh.SpecialFolders.Item(“StartMenu”);         //Folder that contains shortcuts that appear in the current user's start menu
    msg += “nStartup:n   ”           + wsh.SpecialFolders.Item(“Startup”);           //Folder that contains shortcuts to applications that run automatically when the current user logs on to the system
    msg += “nTemplates:n   ”         + wsh.SpecialFolders.Item(“Templates”);         //Folder that contains application template files specific to the current user

    //Display the string

    //Kill the WSH control to be sure Windows Script Host (JScript) retains no references to it and will shut down cleanly
    wsh         = null;[/code]

    See also: “Script Example: Reading Windows Environment Variables” http://forums.xmetal.com/index.php/topic,27.0.html

    External References:


  • You must be logged in to reply to this topic.

Lost Your Password?