How Can I Change the Size of the Temporary Internet Files Folder?

ScriptingGuy1

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I change the amount of disk space set aside for Internet Explorer’s temporary files folder?

— AD

SpacerHey, Scripting Guy! AnswerScript Center

Hey, AD. The first draft of this column we were able to bang out in no time; after all, it consisted entirely of this:

Beats us.

But after discussing how valuable an answer like that would be to our customers, and after realizing that this is the month when we’re supposed to write up our performance reviews, we decided maybe we’d look into this a little further. And although it took a little bit of research, we were able to come up with an answer. (Something you can bet we’ll feature very prominently on our performance review, right after the note that, “At least this year we didn’t set anything on fire.” Between those two items, this might be our best review yet.)

In case you aren’t sure what AD is referring to, start up Internet Explorer and select Internet Options from the Tools menu. In the Internet Options dialog box, on the General tab, click Settings. You should see a dialog box similar to this:

Internet Explorer


What AD would like to do is write a script that can change the Amount of disk space to use value (which, in this example, is set to 447 MB). We have good news for you, AD. You don’t have to write this script; we’ve already written it for you:

Const HKEY_CURRENT_USER = &H80000001

strComputer = “.”

Set objRegistry = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content” strValueName = “CacheLimit” dwValue = 358400 objRegistry.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

strKeyPath = “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Content” strValueName = “CacheLimit” dwValue = 358400 objRegistry.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

As it turns out, the amount of disk space set aside for temporary Internet files is regulated by two registry values:

HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content\CacheLimit

HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Content\CacheLimit

To change the size from 447 MB all we have to do is change the value of these two registry entries.

And that’s exactly what our script does. The script begins by defining a constant named HKEY_CURRENT_USER and setting the value to &H80000001; we’ll use that later on to tell the script that we want to work with the HKEY_CURRENT_USER portion of the registry. We then connect to the WMI service on the local computer, and, more specifically, to the StdRegProv class.

The next three lines of code are used to assign values to three different variables:

strKeyPath = “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content”
strValueName = “CacheLimit”
dwValue = 358400

The variable strKeyPath represents the path within the HKEY_CURRENT_USER portion of the registry; strValueName represents the registry value we want to change (in this case, CacheLimit). We use the variable dwValue to indicate the new size for the Temporary Internet Files folder. It’s important to note that, although the disk space amount is shown in megabytes in the Internet Explorer UI, the value stored in the registry is stored as kilobytes. That means we need to do a little math here. For example, suppose we want to set the disk space amount to 350 megabtes. In that case, we must multiply 350 by 1024; that will give us 358400 kilobytes. And that’s the value we assign to the variable dwValue. To set aside 238 megabytes multiply 238 by 1024 and assign that value (243712) to dwValue.

To actually change the value in the registry all we have to do is call the SetDWORDValue method, passing the appropriate variables as parameters:

objRegistry.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

We then repeat the process for the second registry value. The next time you start Internet Explorer you should see that the amount of disk space set aside for temporary Internet files has changed:

Internet Explorer


Now if only we could write a script that would go in and change our performance review scores as easily as this script changes the Internet Explorer cache size….

0 comments

Discussion is closed.

Feedback usabilla icon