(imported topic written by Lee Wei)
I helped someone with the following issue and spent some time creating a usable Manage Property. So I thought of sharing it.
The original problem statement and request:
"I have a question about scripts for checking the size of folders.
Outlook Express 6 has a big problem regarding the email folder size.
Once the size of its mail folder gets to a certain limit (I don’t remember the exact number), it would have a risk of crashing."
This is an interesting query that goes beyond getting the size of a folder.
NOTE: Please note that the query is resource intensive, and should not be run often. The evaluation interval should be set very long, for example, every 2 or 7 days.
The written relevance will do the following:
-
First check to make sure that someone is logon to the computer, otherwise, it returns “No login user”.
-
Verifies that Outlook Express is configured for the user, or return “No Outlook Express account”.
-
Locate the folder where the Outlook Express files are located in the following registry, and return the size of the entire folder in MB.
(HKEY_CURRENT_USER\Identities{31391EF3-B3AC-4F12-94D8-DC2DA45E9526}\Software\Microsoft\Outlook Express\5.0\Store Root)
- If there are more than one Identity configured for Outlook Express, the Main (also call Default) identity will be used.
Here is the Relevance statement:
if exists (current user) then (if exists (value “Store Root” of Key (“HKEY_USERS” & (name of key whose (value “Logon User Name” of key “Explorer” of key “CurrentVersion” of key “Windows” of key “Microsoft” of key “Software” of it = name of current user) of key “HKEY_USERS” of registry) & “\Identities” & (Value “Default User ID” of Key (“HKEY_USERS” & (name of key whose (value “Logon User Name” of key “Explorer” of key “CurrentVersion” of key “Windows” of key “Microsoft” of key “Software” of it = name of current user) of key “HKEY_USERS” of registry) & “\Identities”) of registry as string) & “\Software\Microsoft\Outlook Express\5.0”) of registry) then (sum of sizes of descendants of folder(preceding text of last “” of ((Value “Local Settings” of Key (“HKEY_USERS” & (name of key whose (value “Logon User Name” of key “Explorer” of key “CurrentVersion” of key “Windows” of key “Microsoft” of key “Software” of it = name of current user) of key “HKEY_USERS” of registry) & “\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders”) of registry as string) & (following text of first “Settings” of (value “Store Root” of Key (“HKEY_USERS” & (name of key whose (value “Logon User Name” of key “Explorer” of key “CurrentVersion” of key “Windows” of key “Microsoft” of key “Software” of it = name of current user) of key “HKEY_USERS” of registry) & “\Identities” & (Value “Default User ID” of Key (“HKEY_USERS” & (name of key whose (value “Logon User Name” of key “Explorer” of key “CurrentVersion” of key “Windows” of key “Microsoft” of key “Software” of it = name of current user) of key “HKEY_USERS” of registry) & “\Identities”) of registry as string) & “\Software\Microsoft\Outlook Express\5.0”) of registry as string)))) / 1048576) as string & " MB" else “No Outlook Express account”) else “No login user”
Although the relevance looks very long, it is composed of smaller queries to resolve specific information we need.
Issue 1: When the BES Client runs on a computer, it runs as the SYSTEM account, and the HKEY_CURRENT_USER hive is different than the actual login user. We can use the following relevance to dynamically return the appropriate hive from HKEY_USERS instead.
Q: (name of key whose (value “Logon User Name” of key “Explorer” of key “CurrentVersion” of key “Windows” of key “Microsoft” of key “Software” of it = name of current user) of key “HKEY_USERS” of registry)
A: S-1-5-21-1606980848-1767777339-682003330-2286
Issue 2: An end-user can setup multiple Identities for his/her Outlook Express application. Each identity will have a different folder of files. The query is currently written to return only the disk usage for the Main Identity. This is done with looking at the “HKEY_CURRENT_USER\Identities\Default User ID” registry key. The relevance can be modified to report the folder size of the “Last User ID” by using the identity key at “HKEY_CURRENT_USER\Identities\Last User ID”.
Q: (Value “Default User ID” of Key (“HKEY_USERS” & (name of key whose (value “Logon User Name” of key “Explorer” of key “CurrentVersion” of key “Windows” of key “Microsoft” of key “Software” of it = name of current user) of key “HKEY_USERS” of registry) & “\Identities”) of registry as string)
A: {31391EF3-B3AC-4F12-94D8-DC2DA45E9526}
Issue 3: The Outlook Express folder name located at registry key “HKEY_CURRENT_USER\Identities{31391EF3-B3AC-4F12-94D8-DC2DA45E9526}\Software\Microsoft\Outlook Express\5.0\Store Root” uses an environment variable %25UserProfile%25 that needs to be expanded appropriately to retrieve a usable directory name.
Q: (Value “Local Settings” of Key (“HKEY_USERS” & (name of key whose (value “Logon User Name” of key “Explorer” of key “CurrentVersion” of key “Windows” of key “Microsoft” of key “Software” of it = name of current user) of key “HKEY_USERS” of registry) & “\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders”) of registry as string)
A: C:\Documents and Settings\lee_wei\Local Settings
Issue 4: How do I calculate the size of a folder and return the size in MB. This is original question and the key is using the “descendants of folders” object.
Q: (sum of sizes of descendants of folder “C:\Documents and Settings\lee_wei\Local Settings\Application Data\Identities{31391EF3-B3AC-4F12-94D8-DC2DA45E9526}\Microsoft\Outlook Express” / 1048576) as string & " MB"
A: 0 MB