[THIN] Re: Moving the Windows Pagefile by scripts ?

  • From: "Mark Schill" <meson3902@xxxxxxxxx>
  • To: thin@xxxxxxxxxxxxx
  • Date: Thu, 13 Apr 2006 08:27:31 -0400

Shane,

You can use the following vbscript excerpt to do what you need.


This is the actual script section that sets the page file size and location.
The first number is the inital size and the second number is the size it can
grow to. You can add/remove additional page files by adding/removing
elements in the array.

 arrPageFiles = Array("C:\PageFile.sys 4095 4095", "D:\PageFile.sys 4095
4095")
 RegWrite "HKLM", "REG_MULTI_SZ", "SYSTEM\CurrentControlSet\Control\Session
Manager\Memory Management", "PagingFiles", arrPageFiles


And this is the RegWrite function that I call in the script. It uses WMI to
make the changes.


= ***********************************************************************
'= Function Name: RegWrite( )
'= Purpose:    Creates a value, if it does not exist, and writes a value
'=
'= Arguments Supplied:  strRoot - registry subtree
'=                      strType - value type
'=                      strPath - path of value
'=                      strName - name of value
'=                      unkValue - value contents (varies by type)
'= Return Value:        <NONE>
'= Function Calls:      <NONE>
'= ***********************************************************************
Function RegWrite( ByVal strRoot, ByVal strType, ByVal strPath, ByVal
strName, ByVal unkValue )


  Dim hexRoot, intType
  Dim objReg
  Const strComputer = "."

  '= Convert string value into native hexadecimial value
  Select Case strRoot
    Case "HKCR"                hexRoot = &H80000000
    Case "HKCU"                hexRoot = &H80000001
    Case "HKLM"                hexRoot = &H80000002
    Case "HKEY_USERS"          hexRoot = &H80000003
    Case "HKEY_CURRENT_CONFIG" hexRoot = &H80000005
  End Select

  '= Convert value type into native integer format
  Select Case strType
    Case "REG_SZ"        intType = 1
    Case "REG_EXPAND_SZ" intType = 2
    Case "REG_BINARY"    intType = 3
    Case "REG_DWORD"     intType = 4
    Case "REG_MULTI_SZ"  intType = 7
  End Select

  '= If in debug mode print out the
arguments

  ' If blnDebug Then
'     WScript.StdOut.WriteLine "Root = " & Hex(hexRoot)
'     WScript.StdOut.WriteLine "Type = " & intType
'     WScript.StdOut.WriteLine "Path = " & strPath
'     WScript.StdOut.WriteLine "Name = " & strName
'     WScript.StdOut.WriteLine "Value = " & unkValue
'   End If

  '= Connect to WMI of specified target
  Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
      strComputer & "\root\default:StdRegProv")

  '= Create Key if it does not already exist
  objReg.CreateKey hexRoot, strPath

  '= Call Write methode depending on value type
  Select Case intType
    Case 1
      objReg.SetStringValue hexRoot, strPath, strName, unkValue
    Case 2
      objReg.SetExpandedStringValue hexRoot, strPath, strName, unkValue
    Case 3
      '= NOTE: Writing BINARY reg types is not available
    Case 4
      objReg.SetDWORDValue hexRoot, strPath, strName, unkValue
    Case 7
      objReg.SetMultiStringValue hexRoot, strPath, strName, unkValue
  End Select

  '= If error occurs, then return 1 for the value of the function
  '= NOTE: WMI does not appear to return any error objects.
  If Err.Number <> 0 Then
    WScript.Echo "Error: " & Err.Number & " - " & Err.Description
    RegWrite = 1
  End If

End Function
'= ***********************************************************************


On 4/12/06, Shane A Broomhall (Aust) <shaneb@xxxxxxxxxxxxxxxxxx> wrote:
>
>  HI All,
>
>
>
> I am working for a company who builds its servers via RIS, and then uses
> scripts to modify them for specific services.  What we are hoping to be able
> to do is to be able to specify that our page file will be on a different
> partition D or E, and a fixed size in the script which does this
> modification. The current scripts are batch (CMD) files.
>
>
>
> Can anyone provide me with some tips on how to get the pagefile moved and
> to a specific size ?
>
>
>
> We are using Windows 2003 server Service Pack 1.
>
>
>
> Thanks in advance
>
>
>
>
>
> Shane Broomhall
>
>
>
> Australia
>
>
>



--
Mark E. Schill

Other related posts: