Ok, so this is a bit of a wierd one.

During our automated build of Windows Server 2008, one of the options we
would like to set is the size of the Page File. Because we have servers with
lots of RAM and often not large system drives we like to set them manually,
this also helps avoid page file fragmentation.

In Server 2008, before you can set the page file manually, you need to
disable the automatic management of the page file using the
win32_ComputerSystem.AutomaticManagedPagefile property.

When I set this property to false using either a PowerShell window or WMIC
from the command-line it works nicely. However, when I try to set this
property using VBScript it fails to save the property. I have used the
following script:

***START SCRIPT***
Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate,
(CreatePageFile)}!root\cimv2")
For Each objCompSys In objWMIService.ExecQuery("SELECT * FROM
Win32_ComputerSystem")
objCompSys.AutomaticManagedPagefile = False
WScript.Echo objCompSys.AutomaticManagedPagefile
Next
***END SCRIPT***

The script runs without errors AND outputs '0' to show that the setting has
been changed. However, when I then re-run the script without setting the
property, it outputs '-1' to show the setting is 'True'. I'm not aware of
normally needing to make any kind of 'update' to WMI, it normally updates as
you change a property, is there something that I'm doing wrong here?

I've ruled out (I think) any kind of permissions issues by including the
.Rename method in the script which successfully renamed the machine so I know
the interface works.

Any help would be appreciated

Regards

Brendan

RE: Why Can't You Set the PageFile on Server 2008 using VBScript and W by urkec

urkec
Thu Apr 24 10:17:00 CDT 2008

"Brendan Saunders" wrote:

> Ok, so this is a bit of a wierd one.
>
> During our automated build of Windows Server 2008, one of the options we
> would like to set is the size of the Page File. Because we have servers with
> lots of RAM and often not large system drives we like to set them manually,
> this also helps avoid page file fragmentation.
>
> In Server 2008, before you can set the page file manually, you need to
> disable the automatic management of the page file using the
> win32_ComputerSystem.AutomaticManagedPagefile property.
>
> When I set this property to false using either a PowerShell window or WMIC
> from the command-line it works nicely. However, when I try to set this
> property using VBScript it fails to save the property. I have used the
> following script:
>
> ***START SCRIPT***
> Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate,
> (CreatePageFile)}!root\cimv2")
> For Each objCompSys In objWMIService.ExecQuery("SELECT * FROM
> Win32_ComputerSystem")
> objCompSys.AutomaticManagedPagefile = False
> WScript.Echo objCompSys.AutomaticManagedPagefile
> Next
> ***END SCRIPT***
>
> The script runs without errors AND outputs '0' to show that the setting has
> been changed. However, when I then re-run the script without setting the
> property, it outputs '-1' to show the setting is 'True'. I'm not aware of
> normally needing to make any kind of 'update' to WMI, it normally updates as
> you change a property, is there something that I'm doing wrong here?
>
> I've ruled out (I think) any kind of permissions issues by including the
> .Rename method in the script which successfully renamed the machine so I know
> the interface works.
>
> Any help would be appreciated
>
> Regards
>
> Brendan


It looks like AutomaticManagedPagefile is a property, not a method:

http://msdn2.microsoft.com/en-us/library/aa394102(VS.85).aspx


I can't test this, but you may need to use SWbemObject.Put_ to save the
changed object:


objCompSys.AutomaticManagedPagefile = False
objCompSys.Put_

WScript.Echo objCompSys.AutomaticManagedPagefile


--
urkec

Re: Why Can't You Set the PageFile on Server 2008 using VBScript and W by Alex

Alex
Thu Apr 24 11:46:46 CDT 2008

That was what I thought should work as well, but when I did a test on a
Win2008 VM, I get a generic WMI failure. This may be due to some subtle
modification in how WMI is working or due to the authentication level set. I
did find that the analogous operation in wmic seemed to work fine, including
setting the pagefile size:

wmic computersystem where name="%computername%" set
AutomaticManagedPagefile=false
wmic pagefileset set InitialSize=1536,MaximumSize=1536

I have no clue why I'm running into problems using the WSH variant; Put_ has
worked just fine for me in the past. I'd be interested in seeing what
Brendan encounters.

"urkec" <urkec@discussions.microsoft.com> wrote in message
news:A1666153-8DA2-4890-982B-0A61247EFDEA@microsoft.com...

> It looks like AutomaticManagedPagefile is a property, not a method:
> http://msdn2.microsoft.com/en-us/library/aa394102(VS.85).aspx
>
>
> I can't test this, but you may need to use SWbemObject.Put_ to save the
> changed object:
>
>
> objCompSys.AutomaticManagedPagefile = False
> objCompSys.Put_
>
> WScript.Echo objCompSys.AutomaticManagedPagefile
>
>
> --
> urkec


Re: Why Can't You Set the PageFile on Server 2008 using VBScript a by BrendanSaunders

BrendanSaunders
Fri Apr 25 01:28:00 CDT 2008

Hi Guys

I'd tried using .Put_ in the script to save the object back to WMI, as I
used this in my tests in PowerShell and encountered the 'Generic Failure'
issue. What I did notice, however, was that it had still changed the
.AutomaticManagedPagefile property in the live system despite generating the
error.
In this case I've simply put an 'On Error Resume Next' before this specific
piece of code and an 'Err.Clear' after it and it's working quite nicely.
Strange, Huh?

Thanks for the suggestions, hope this thread helps anyone else encountering
the same issue.

"Alex K. Angelopoulos" wrote:

> That was what I thought should work as well, but when I did a test on a
> Win2008 VM, I get a generic WMI failure. This may be due to some subtle
> modification in how WMI is working or due to the authentication level set. I
> did find that the analogous operation in wmic seemed to work fine, including
> setting the pagefile size:
>
> wmic computersystem where name="%computername%" set
> AutomaticManagedPagefile=false
> wmic pagefileset set InitialSize=1536,MaximumSize=1536
>
> I have no clue why I'm running into problems using the WSH variant; Put_ has
> worked just fine for me in the past. I'd be interested in seeing what
> Brendan encounters.
>
> "urkec" <urkec@discussions.microsoft.com> wrote in message
> news:A1666153-8DA2-4890-982B-0A61247EFDEA@microsoft.com...
>
> > It looks like AutomaticManagedPagefile is a property, not a method:
> > http://msdn2.microsoft.com/en-us/library/aa394102(VS.85).aspx
> >
> >
> > I can't test this, but you may need to use SWbemObject.Put_ to save the
> > changed object:
> >
> >
> > objCompSys.AutomaticManagedPagefile = False
> > objCompSys.Put_
> >
> > WScript.Echo objCompSys.AutomaticManagedPagefile
> >
> >
> > --
> > urkec
>
>