Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create New Page File Size

Status
Not open for further replies.

Jaws25

IS-IT--Management
Joined
Sep 4, 2003
Messages
11
Location
US
The code below will display the pagefile min and max size as well as the total physical memory size. I need to set the min and max to equal 1.5 * physical memory size so that when the computer reboots, it retains the new settings.

Any help would be greatly appreciated! = )


'*************************
strComputer = "."
PageFile
MemCount
CreatePageFileSize

Sub PageFile()
On Error Resume Next
Set objWMIServicePageFile = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems1 = objWMIServicePageFile.ExecQuery("Select * from Win32_PageFileSetting",,48)
For Each objItem in colItems1
Wscript.Echo "InitialSize: " & objItem.InitialSize
Wscript.Echo "MaximumSize: " & objItem.MaximumSize
Next
End Sub


Sub MemCount()
On Error Resume Next
Set objWMIServicePhysMem = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems2 = objWMIServicePhysMem.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems2
Wscript.Echo "Total Physical Memory: " & objItem.TotalPhysicalMemory
Next
 
Set this registry key...

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PagingFiles (REG_MULTI_SZ)

Mine says "C:\pagefile.sys 384 768". I changed it to "C:\pagefile.sys 768 1024", rebooted and everything checked out OK. The value is a multi-string so adding a null value (Chr(0)) between entries allows you to span the page file across drives.


HtH,

Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Thanks Rob for the help. However I did already know the registry location and use. Unfortunately this won't work for what I am trying to accomplish. I need to have this run on a variety of machines each with a different amount of ram. The process needs to be automated with no user input. I am however much farther than this morning. Here is what i have now.

'****************
Dim objWMIService, objWMIServicePhysMem, colItems1, colItems2, strComputer, objItem
Dim bytes, setbytes, megabytes, objPageFile

strComputer = "."
MemCount
PageFile

Sub MemCount()
Set objWMIServicePhysMem = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems2 = objWMIServicePhysMem.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems2
Wscript.Echo "Total Physical Memory: " & objItem.TotalPhysicalMemory
bytes = objItem.TotalPhysicalMemory
If Bytes >= 1073741824 Then
SetBytes = (Bytes / 1024 / 1024 / 1024)
ElseIf Bytes >= 1048576 Then
SetBytes = (Bytes / 1024 / 1024)
ElseIf Bytes >= 1024 Then
SetBytes = (Bytes / 1024)
ElseIf Bytes < 1024 Then
SetBytes = Fix(Bytes)
End If
WScript.Echo setbytes
megabytes = CInt(setbytes * 1.5)
Next
End Sub


Sub PageFile()
Set objWMIService = GetObject(&quot;winmgmts:\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colItems1 = objWMIService.ExecQuery(&quot;Select * from Win32_PageFileSetting&quot;)

For Each objPageFile in colItems1
objPageFile.InitialSize = megabytes
objPageFile.MaximumSize = megabytes
objPageFile.Put_
Next
End Sub

'****************

The error I recieve is this:
SWbemObjectEx: Provider does not support put extensions

Any advice would be appreciated.
 
strComputer = &quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:&quot; _
& &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colPageFiles = objWMIService.ExecQuery _
(&quot;Select * from Win32_PageFileSetting&quot;)
For Each objPageFile in colPageFiles
objPageFile.InitialSize = 300
objPageFile.MaximumSize = 600
objPageFile.Put_
Next

got same code off MS's site as you have and ran it on my machine without err.
im on wxp with sp1 and im full local admin
 
infact ran your complete script on my machine and works perfect!! i should really give you a star for a good post!!!
i presume your OS is different from mine. is your WMI version an older one???
 
Hehe, thanks! =) I did some more testing and reading and found that my script did work on NT. However, I still can't get it to work on XP. I found an ms link that states that the there seems to be a difference regarding this object and how its call/referenced with XP. After reading that I was surprised to see that you were successful MrMovie. This gives me more hope though. As soon as I get to work I'll be testing more! =)
 
Mr. Movie,

I have all the winxp patches/updates. Could you check your version of the following for me? Thanks!

WSH Version: 5.6
VBScript Version: 5.6
WMI Version: 2600.0000
ADSI Version: 5,0,00,0
 
Ok, apparently the script I wrote works on every machine but mine! I have now tested it on other XP machines as well as 2k and 2k3 and they all work. Guess I need to rebuild! =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top