ReadMe.SetEnvVars.txt -- CCleaner - Optional VBScript Module Documentation for additional environment variables for winapp2.ini (and the like). 2010-12-03 Moonbase *** This is a Unicode file (UTF-16LE). You can use "Editor" to display it. *** *** IF YOU CAN’T READ THIS WELL, switch your editor to WRAP LONG LINES. *** Copyright ©2010 Matthias C. Hormann (aka Moonbase). All Rights Reserved. This file and it's contents may not be copied or distributed without the express permission of the author. --- CONTENTS A. Instructions for the Impatient B. The Good, the Bad, and the Ugly C. Trying to make things a little easier D. Using it from inside CCleaner E. Using the new variables in "winapp2.ini" F. Buy me a beer? Buy me a beer! ;-) G. Still here? Wow. The List of Variables! --- A. INSTRUCTIONS FOR THE IMPATIENT 1. Copy "SetEnvVars.vbs" and "winsys2.ini" into your CCleaner program folder. 2. Double-click and execute "SetEnvVars.vbs" at least once. (No harm will be done if it’s run more than one time.) 3. If you have your own "winapp2.ini" file, you may now modify it to use the extra, all-new, environment variables. And enjoy the extra functionality. 4. If you switch systems, or the system’s locale (language), run "SetEnvVars.vbs" again. 5. All this should work on Windows 2000, XP, Vista, and Seven. Maybe more ... --- B. THE GOOD, THE BAD, AND THE UGLY Now Windows has evolved over some decades. It has become quite a complicated operating system, and has a bunch of features, like localization. Sadly enough, to do "everything right", you almost need to be a professional programmer. Then there’s a lot of nice freeware, shareware and open source software out there. Often made with lots of good will, but not taking each and every situation into account. Or trying to help with some add-ons, and only thinking about the own country (the U.S., mostly). But Windows’ user base out there is ENORMOUS. And even good software tends to break, or work erratically, often due to minor oversights. Or just not sitting in Redmond and have all the documentation available. Just think about our beloved "My Documents" folder, often containing even more stuff, like "My Pictures", "My Music", and "My Videos". It’s in English, so it’s universal, right? So where’s the harm in hard-coding something like "C:\Documents and Settings\" plus the username, plus "\Local Settings\Application Data" into an application? It will break. Or is already broken. The above example is from an English-language Windows XP system. On a German-language Windows XP, this would look like C:\Dokumente und Einstellungen\username\Lokale Einstellungen\Anwendungsdaten Or on a Spanish system C:\Documents and Settings\username\Configuración local\Datos de programa Or even C:\Users\username\AppData\Local if you’re running Windows 7 with the English locale active. See what I mean? So, if you’re a programmer, DON’T USE HARD-CODED STRINGS! If anyhow possible, let the operating system give you the correct names, paths and values. You will enjoy less bug reports, less problems, and your software will have lots and lots of happy users. Even in Germany, or Russia, or Madagascar ... anywhere. --- C. TRYING TO MAKE THINGS A LITTLE EASIER Things are often not as easy as they seem. I’d LOVE to see CCleaner’s programmer implement all these features into his software, so we all could get rid of things like hard-coded "My Documents" in, say "winapp2.ini". To help out for a while, I decided to write a small helper module in VBScript (yuk!), since VBScript is supported by CCleaner and many, if not most, users will have the Windows Scripting Host enabled. CCleaner CAN use so-called "Environment variables" (known by many from the old DOS batch file programming times), so we can set up most oft the "important" so-called "Windows Special Folders" as environment variables. The nice side-effect is that you can also use them in your own scripts or batch files later on. Or in CCleaner, preferably in the famous "winapp2.ini", which is a file you can edit yourself (or download from Piriform’s forums), and which helps to specify additional cleansing actions. We store most of the "well known" special places as variables in the "user" environment. These get stored in the registry (HKCU) and thus will survive a system restart. Since the variables are different for each Windows user, you’ll have to execute SetEnvVars.vbs under each Windows user account that you plan to run CCleaner under. Using always the same variable names, we can be sure that CCleaner — and your fine-tuned "winapp2.ini" — will always point its cleansing activities at the right places. Independent of OS version or language! As a bonus, you can always use the same environment variables in your batch files or other scripts. You know you can easily set them up again anytime using my "SetEnvVars.vbs". You can even use the "special places" with Windows Explorer: Just try to enter the following examples into Windows Explorer’s address bar: %Music% (jumps to your "My Music" folder) %ControlPanelFolder% (shows your system control panel) %ConnectionsFolder% (shows your connections) %LocalAppData% (shows your application’s data on this machine) %RoamingAppData% (shows the app data you can "take with you", i.e., in a domain) Be aware that not each and every variable works on every system! My script should handle these situations gracefully, though. If you want to peek around a little, feel free to open SetEnvVars.vbs in the editor of your choice and read all the comments inside. In line 19, you can also set the variable "debug" to TRUE and run the script again. It will pop up a message box stating what it is doing for each and every variable (about 56). This might come in handy for Windows 8 … Enjoy! :-) --- D. USING IT FROM INSIDE CCLEANER If you’re not already using a "winsys2.ini" file, copy mine into your CCleaner program folder. It will add an extra menu entry called "Add Special Folder name variables" under "Advanced" on the "Windows" tab and enable it. A warning pops up whenever you check the button "Add Special Folder name variables": "This will add extra environment variables to your User Environment for later use in 'winapp2.ini'. This needs to be done only once (or if you changed Special Windows Folders). To correctly enable the newly added Special Folder Name variables, you may have to run CCleaner once, then restart it. (It doesn't hurt leaving this option enabled.)" This is just to remind you that things might have changed, and the SetEnvVars.vbs script needs to be run at least once before the extra variables can be used. If you have run SetEnvVars.vbs BEFORE you started CCleaner, you do not need to run it again from within CCleaner. If you do, it won’t hurt. --- E. USING THE NEW VARIABLES IN "winapp2.ini" Let’s take a practical example using the "winapp2.ini" file you can download from Piriform’s forum at http://forum.piriform.com/index.php?showtopic=29438 (Topic "Get the Latest Winapp2.ini File") Open the file in your favorite editor, and search for this section: [CDex*] LangSecRef=3024 Detect=HKLM\SOFTWARE\CDex Default=False FileKey1=%UserProfile%\My Documents\My Music\CDDB|*.txt We can easily see that this entry wouldn’t work on a German Windows XP, or on Windows 7. Depending on the system, the above FileKey1 expands to: English Windows XP (okay): C:\Documents and Settings\username\My Documents\My Music\CDDB\*.txt German Windows XP (BAD): C:\Dokumente und Einstellungen\username\My Documents\My Music\CDDB\*.txt The correct path would be: C:\Dokumente und Einstellungen\username\Eigene Dateien\Eigene Musik\CDDB\*.txt English Windows 7 (BAD): C:\Users\username\My Documents\My Music\CDDB\*.txt The correct path would be: C:\Users\username\Music\CDDB\*.txt We will now change FileKey1 so that it works using the new environment variables my script has set up for you: FileKey1=%Music%\CDDB|*.txt Which expands correctly on various systems: C:\Documents and Settings\username\My Documents\My Music\CDDB\*.txt C:\Dokumente und Einstellungen\username\Eigene Dateien\Eigene Musik\CDDB\*.txt C:\Users\username\Music\CDDB\*.txt Great, ain’t it? Of course I have tried all these out on several systems, but if you have CDex (or any other app mentioned in winapp2.ini), go try it out for yourself! CCleaner should not be running while you’re editing winapp2.ini. Just start it after you have finished your edits and saved the file. --- F. BUY ME A BEER? BUY ME A BEER! ;-) If this was helpful for you and you feel like it, you can buy me a beer (or a cup of coffee) using the Paypal links on my homepage: http://www.kaufen-ist-toll.de/moonbase#buyme Don’t feel obliged, though. You don’t HAVE to. I’m perfectly happy if you like it and I could help you in any way. And I believe in Open Source, sharing knowledge and free access for all. Enjoy! moonbase (at) quantentunnel (dot) de --- G. STILL HERE? WOW. THE LIST OF VARIABLES! Here now is the list of variables that my script handles. Remember that not all of them might be available on any particular Windows version! Variables that are not available in the Windows version you’re running will be unset (removed) from the environment. Be aware that (currently) an unset variable, if used in construction of a CCleaner key, CAN lead to unpredicted results (i.e., trying to check for and/or cleaning a directory that doesn’t exist). Some of the variables return CLSIDs, which are not per se useful in CCleaner file operations, but can be used as input in Windows Explorer’s address bar. These are listed separately. All variables are listed in alphabetical order (per section). 1. VARIABLES THAT MAKE SENSE WITH CCLEANER (YOU SHOULD USE THESE) These are most useful to use with CCleaner file operations. They will access the "right" special folders on almost any Windows 2000, XP, Vista or 7 machine, independent of its locale settings. %CDBurning% (CSIDL_CDBURN_AREA, 0x3b) V6.0: The file system directory that acts as a staging area for files waiting to be written to a CD. A typical path is C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\CD Burning. %CommonFavorites% (CSIDL_COMMON_FAVORITES, 0x1f) The file system directory that serves as a common repository for favorite items common to all users. %CommonOEMLinks% (CSIDL_COMMON_OEM_LINKS, 0x3a) This value is recognized in Windows Vista for backward compatibility, but the folder itself is no longer used. I’ve seen it come back in Windows 7, though. %CommonStartup% (CSIDL_COMMON_STARTUP, 0x18) The file system directory that contains the programs that appear in the Startup folder for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs\Startup. %Cookies% (CSIDL_COOKIES, 0x21) The file system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\username\Cookies. %DesktopDirectory% (CSIDL_DESKTOPDIRECTORY, 0x10) The file system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself). A typical path is C:\Documents and Settings\username\Desktop. %Favorites% (CSIDL_FAVORITES, 0x06) The file system directory that serves as a common repository for the user's favorite items. A typical path is C:\Documents and Settings\username\Favorites. %History% (CSIDL_HISTORY, 0x22) The file system directory that serves as a common repository for Internet history items. %InternetCache% (CSIDL_INTERNET_CACHE, 0x20) V4.72: The file system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\username\Local Settings\Temporary Internet Files. %LocalAppData% (CSIDL_LOCAL_APPDATA, 0x1c) V5.0: The file system directory that serves as a data repository for local (nonroaming) applications. A typical path is C:\Documents and Settings\username\Local Settings\Application Data. %Music% (CSIDL_MYMUSIC, 0x0d) The file system directory that serves as a common repository for music files. A typical path is C:\Documents and Settings\User\My Documents\My Music. %Personal% (CSIDL_PERSONAL, 0x05) V6.0: The virtual folder that represents the My Documents desktop item. This is equivalent to CSIDL_MYDOCUMENTS. Previous to V6.0: The file system directory used to physically store a user's common repository of documents. A typical path is C:\Documents and Settings\username\My Documents. This should be distinguished from the virtual My Documents folder in the namespace. To access that virtual folder, use SHGetFolderLocation, which returns the ITEMIDLIST for the virtual location, or refer to the technique described in Managing the File System. %Pictures% (CSIDL_MYPICTURES, 0x27) V5.0: The file system directory that serves as a common repository for image files. A typical path is C:\Documents and Settings\username\My Documents\My Pictures. %Profile% (CSIDL_PROFILE, 0x28) V5.0: The user's profile folder. A typical path is C:\Users\username. Applications should not create files or folders at this level; they should put their data under the locations referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA. However, if you are creating a new Known Folder the profile root referred to by CSIDL_PROFILE is appropriate. %ProgramData% (CSIDL_COMMON_APPDATA, 0x23) V5.0: The file system directory that contains application data for all users. A typical path is C:\Documents and Settings\All Users\Application Data. This folder is used for application data that is not user specific. For example, an application can store a spell-check dictionary, a database of clip art, or a log file in the CSIDL_COMMON_APPDATA folder. This information will not roam and is available to anyone using the computer. %ProgramFiles% (CSIDL_PROGRAM_FILES, 0x26) V5.0: The Program Files folder. A typical path is C:\Program Files. %ProgramFilesCommon% (CSIDL_PROGRAM_FILES_COMMON, 0x2b) V5.0: A folder for components that are shared across applications. A typical path is C:\Program Files\Common. Valid only for Windows XP. %ProgramFilesCommonX86% (CSIDL_PROGRAM_FILES_COMMONX86, 0x2c) %ProgramFilesX86% (CSIDL_PROGRAM_FILESX86, 0x2a) %PublicDesktop% (CSIDL_COMMON_DESKTOPDIRECTORY, 0x19) The file system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop. %PublicDocuments% (CSIDL_COMMON_DOCUMENTS, 0x2e) The file system directory that contains documents that are common to all users. A typical path is C:\Documents and Settings\All Users\Documents. %PublicMusic% (CSIDL_COMMON_MUSIC, 0x35) V6.0: The file system directory that serves as a repository for music files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Music. %PublicPictures% (CSIDL_COMMON_PICTURES, 0x36) V6.0: The file system directory that serves as a repository for image files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Pictures. %PublicVideos% (CSIDL_COMMON_VIDEO, 0x37) V6.0: The file system directory that serves as a repository for video files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Videos. %Recent% (CSIDL_RECENT, 0x08) The file system directory that contains shortcuts to the user's most recently used documents. A typical path is C:\Documents and Settings\username\My Recent Documents. To create a shortcut in this folder, use SHAddToRecentDocs. In addition to creating the shortcut, this function updates the Shell's list of recent documents and adds the shortcut to the My Recent Documents submenu of the Start menu. %RoamingAppData% (CSIDL_APPDATA, 0x1a) V4.71: The file system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\username\Application Data. This CSIDL is supported by the redistributable Shfolder.dll for systems that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed. %Startup% (CSIDL_STARTUP, 0x07) The file system directory that corresponds to the user's Startup program group. The system starts these programs whenever any user logs on. A typical path is C:\Documents and Settings\username\Start Menu\Programs\Startup. %System% (CSIDL_SYSTEM, 0x25) V5.0: The Windows System folder. A typical path is C:\Windows\System32. %SystemX86% (CSIDL_SYSTEMX86, 0x29) A typical path is C:\Windows\System32. %Videos% (CSIDL_MYVIDEO, 0x0e) V6.0: The file system directory that serves as a common repository for video files. A typical path is C:\Documents and Settings\username\My Documents\My Videos. %Windows% (CSIDL_WINDOWS, 0x24) V5.0: The Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\Windows. 2. VARIABLES THAT ARE USEFUL FOR SPECIAL REQUIREMENTS These are intended for more special cases, or declared obsolete, and might not function as intended. You should know what you do, it’s all upon your own risk! %AdminTools% (CSIDL_ADMINTOOLS, 0x30) V5.0: The file system directory that is used to store administrative tools for an individual user. The MMC will save customized consoles to this directory, and it will roam with the user. %AltStartup% (CSIDL_ALTSTARTUP, 0x1d, obsolete, use "Startup") The file system directory that corresponds to the user's nonlocalized Startup program group. This value is recognized in Windows Vista for backward compatibility, but the folder itself no longer exists. %CommonAdminTools% (CSIDL_COMMON_ADMINTOOLS, 0x2f) V5.0: The file system directory that contains administrative tools for all users of the computer. %CommonAltStartup% (CSIDL_COMMON_ALTSTARTUP, 0x1e, obsolete, use "CommonStartup") The file system directory that corresponds to the nonlocalized Startup program group for all users. This value is recognized in Windows Vista for backward compatibility, but the folder itself no longer exists. %CommonPrograms% (CSIDL_COMMON_PROGRAMS, 0x17) The file system directory that contains the directories for the common program groups that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs. %CommonStartMenu% (CSIDL_COMMON_STARTMENU, 0x16) The file system directory that contains the programs and folders that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. %CommonTemplates% (CSIDL_COMMON_TEMPLATES, 0x2d) The file system directory that contains the templates that are available to all users. A typical path is C:\Documents and Settings\All Users\Templates. %Desktop% (CSIDL_DESKTOP, 0x00) The virtual folder that represents the Windows desktop, the root of the namespace. %Documents% (CSIDL_MYDOCUMENTS, 0x0c) V6.0: The virtual folder that represents the My Documents desktop item. This value is equivalent to CSIDL_PERSONAL. %Fonts% (CSIDL_FONTS, 0x14) A virtual folder that contains fonts. A typical path is C:\Windows\Fonts. %LocalizedResourcesDir% (CSIDL_RESOURCES_LOCALIZED, 0x39) %NetHood% (CSIDL_NETHOOD, 0x13) A file system directory that contains the link objects that may exist in the My Network Places virtual folder. It is not the same as CSIDL_NETWORK, which represents the network namespace root. A typical path is C:\Documents and Settings\username\NetHood. %PrintHood% (CSIDL_PRINTHOOD, 0x1b) The file system directory that contains the link objects that can exist in the Printers virtual folder. A typical path is C:\Documents and Settings\username\PrintHood. %Programs% (CSIDL_PROGRAMS, 0x02) The file system directory that contains the user's program groups (which are themselves file system directories). A typical path is C:\Documents and Settings\username\Start Menu\Programs. %ResourceDir% (CSIDL_RESOURCES, 0x38) Windows Vista: The file system directory that contains resource data. A typical path is C:\Windows\Resources. %SendTo% (CSIDL_SENDTO, 0x09) The file system directory that contains Send To menu items. A typical path is C:\Documents and Settings\username\SendTo. %StartMenu% (CSIDL_STARTMENU, 0x0b) The file system directory that contains Start menu items. A typical path is C:\Documents and Settings\username\Start Menu. %Templates% (CSIDL_TEMPLATES, 0x15) The file system directory that serves as a common repository for document templates. A typical path is C:\Documents and Settings\username\Templates. 3. VARIABLES THAT ONLY RETURN CLSIDs These are not useful for CCleaner (but can be for other purposes), because the only return CLSIDs. CLSIDs are globally unique identifiers that identify COM class objects, for instance "%RecycleBinFolder%" will return a CLSID of ::{645FF040-5081-101B-9F08-00AA002F954E} which is the virtual folder that contains the objects in the user's Recycle Bin. %ComputerFolder% (CSIDL_DRIVES, 0x11) The virtual folder that represents My Computer, containing everything on the local computer: storage devices, printers, and Control Panel. The folder can also contain mapped network drives. %ComputersNearMe% (CSIDL_COMPUTERSNEARME, 0x3d) The folder that represents other computers in your workgroup. Usually (only) contains a Workgroup or Domain Name. %ConnectionsFolder% (CSIDL_CONNECTIONS, 0x31) The virtual folder that represents Network Connections, that contains network and dial-up connections. %ControlPanelFolder% (CSIDL_CONTROLS, 0x03) The virtual folder that contains icons for the Control Panel applications. %InternetFolder% (CSIDL_INTERNET, 0x01) A virtual folder for Internet Explorer. %Network% (CSIDL_NETWORK, 0x12) A virtual folder that represents Network Neighborhood, the root of the network namespace hierarchy. %PrintersFolder% (CSIDL_PRINTERS, 0x04) The virtual folder that contains installed printers. %RecycleBinFolder% (CSIDL_BITBUCKET, 0x0a) The virtual folder that contains the objects in the user's Recycle Bin. ---