Windows set page file

SetPageFile

#1 Lancelot

  • .script developer
  • 5013 posts
    • Location: Turkiye/Izmir
    • Interests: *Mechanical stuff and Physics,
      *LiveXP, BartPE, SherpyaXPE,
      *Basketball and Looong Walking,
      *Buying outwear for my girlf (Reason: Girls are stupid about buying bad stuff to make themselves uglier :))
      *Girls (Lyric: Girl. You will be a womann, Soon)
      *Answering questions for «Meaning of life»,
      *Helping people,

      Kung with LiveXP, Fu with Peter 🙂

    • Turkey

    If a utility needs a pagefile, now you have it.

    SetPageFile is Paraglider’s plugin for BartPE (also in .script file), I only wrote a script to use SetPageFile with LiveXP.

    **For now SetPageFile dont work with Imdisk (see gui), and dont work with USB Stick (pendrive)
    Works with RealHD (see picture)
    +Also will work with USB Stick (pendrive) if you use dummyfilter .
    (only tested with LiveXP)

    I hope you like it

    Script v6 info:
    Thanks amalux.
    Custom option added with Startup + ‘Custom Batch’ availability
    Following Amalux post 410
    * When you use «First Drive» option (a1 switch) minimum size not work, page file create on drive with maximum size.
    * When C: D: . options used, page file created with minimum size, but Amalux reports difficulties expansion with minimum size («the program I was testing (VirtualBox) wouldn’t recognize the expandable part»), well an advice: set your minimum size high and/or equal to maximum for C: D. options.

    Now one can easly have pagefile at startup if one has a RealDrive during startup . Script v6 have default settings to create pagefile at startup to demonstrate. But using startup option is risky, read the warning from Amalux post 13

    A note here on running SetPageFile automatically e.g. built into script or added to root of iso as ppapp etc. It’s best to not allow page file on C: or any drive you may need to image from pe (Acronis, Ghost etc.), the active page can cause an error when trying to lock the drive for imaging. If C: is only drive available, better to run SetPageFile manually when needed for VirtualBox etc.

    Additional info, you can not remove pagefile after it is created once .

    #2 JonF

  • .script developer
  • 1185 posts
    • Location: Boston, MA
    • United States

    Interesting. I’ll try it out . when I can.

    I wonder if Joshua’s PreShell could be ported? That’s what I really need; a decision on how big a RAMdisk to set up and whether or not to set up a page file at boot time. Once in a while (once just a few weeks ago) I have to boot on a 128 MB system, and I once booted BartPE on a 64 MB system and managed to do some real work.

    #3 Brito

  • .script developer
  • 10583 posts
    • Location: boot.wim
    • Interests: I’m just a quiet simple person with a very quiet simple life living one day at a time..
    • European Union

    Cool script for pendrives!

    Thank you..

    #4 Lancelot

  • .script developer
  • 5013 posts
    • Location: Turkiye/Izmir
    • Interests: *Mechanical stuff and Physics,
      *LiveXP, BartPE, SherpyaXPE,
      *Basketball and Looong Walking,
      *Buying outwear for my girlf (Reason: Girls are stupid about buying bad stuff to make themselves uglier :))
      *Girls (Lyric: Girl. You will be a womann, Soon)
      *Answering questions for «Meaning of life»,
      *Helping people,

      Kung with LiveXP, Fu with Peter 🙂

    • Turkey

    When some additions made to imdisk, it is possible to make a pagefile on ramdrive during startup to solve issue of «pagefile required» with lots of ready ram (which was my first intention),

    here is what Galapo wrote before about this:

    I think the reason why the pagefile cannot be created on ramdrive in LiveXP is that default ramdrive is created by ImDisk. ImDisk disks aren’t listed under ‘System\MountedDevices’ and so the pagefile is not created.

    I wonder if Joshua’s PreShell could be ported? That’s what I really need; a decision on how big a RAMdisk to set up and whether or not to set up a page file at boot time.

    a cmd shell may be designed for this purpose (to ask at startup), you may use one of the .cmd files which i already put shorcuts to «startmenu\System\SetPageFile_CMD\. «


    For low ram cases, For pendrive,
    I havent tried, but probably putting livexp on usb, and adding SetPageFile_zz_systemdrive.cmd to startup (or you may already use shortcut on startmenu\System\SetPageFile_CMD\. ) may solve some ram issues.

    For low ram cases, For cd,
    if you have a writable real disk partition, why not try one of startmenu\System\SetPageFile_CMD\. shortcuts, or maybe SetPageFile directly and see if it works for you.

    I left decision of using pagefile manual and to ease setting pagefile i put some ready to use .cmd with shorcuts. I hope this works for you.

    Nuno

    #5 sanbarrow

  • Developer
  • 788 posts
    • Location: Germany — Sauerland

    For pendrive,
    I havent tried, but probably putting livexp on usb, and adding SetPageFile_zz_systemdrive.cmd to startup (or you may already use shortcut on startmenu\System\SetPageFile_CMD\. ) may solve some ram issues.

    ? do you have found a way to use setpagefile.exe against a USB-disk or stick ?

    If yes — please explain

    #6 paraglider

  • .script developer
  • 1741 posts
    • Location: NC,USA
    • United States

    SetPageFile only validates the drive being fixed if using its gui. Otherwise all it requires is QueryDosDevice to return the dos device name for the the drive letter and for the kernel function NtCreatePagingFile to actually create the page file. The file name passed to the page file create function is formatted like \ e.g. \Device\HarddiskVolume1\pagefile.sys

    Don’t see the point in creating a page file on a ram drive. The idea of a page file is to swap program memory to disk so you free up memory for other programs. Swapping memory to memory does not gain you anything.

    #7 Lancelot

  • .script developer
  • 5013 posts
    • Location: Turkiye/Izmir
    • Interests: *Mechanical stuff and Physics,
      *LiveXP, BartPE, SherpyaXPE,
      *Basketball and Looong Walking,
      *Buying outwear for my girlf (Reason: Girls are stupid about buying bad stuff to make themselves uglier :))
      *Girls (Lyric: Girl. You will be a womann, Soon)
      *Answering questions for «Meaning of life»,
      *Helping people,

      Kung with LiveXP, Fu with Peter 🙂

    • Turkey

    ? do you have found a way to use setpagefile.exe against a USB-disk or stick ?

    If yes — please explain

    Sorry, i just tried, no. I put a note to avoid misunderstaning in first post. Thanks for me noticing this. I didnt have a USB-stick to test the time i put this script.

    Ps: sorry Nuno.

    Don’t see the point in creating a page file on a ram drive. The idea of a page file is to swap program memory to disk so you free up memory for other programs. Swapping memory to memory does not gain you anything.

    I agree. Only point is in cases a utility checks for a pagefile to startup. Luckly utilites dont do that. So far i found only photoshop55 does that which is not important for pe usage.

    btw, Thanks a lot for everything paraglider

    #8 Lancelot

  • .script developer
  • 5013 posts
    • Location: Turkiye/Izmir
    • Interests: *Mechanical stuff and Physics,
      *LiveXP, BartPE, SherpyaXPE,
      *Basketball and Looong Walking,
      *Buying outwear for my girlf (Reason: Girls are stupid about buying bad stuff to make themselves uglier :))
      *Girls (Lyric: Girl. You will be a womann, Soon)
      *Answering questions for «Meaning of life»,
      *Helping people,

      Kung with LiveXP, Fu with Peter 🙂

    • Turkey

    SetEndOfFile function (fileapi.h)

    Sets the physical file size for the specified file to the current position of the file pointer.

    The physical file size is also referred to as the end of the file. The SetEndOfFile function can be used to truncate or extend a file. To set the logical end of a file, use the SetFileValidData function.

    Syntax

    Parameters

    A handle to the file to be extended or truncated.

    The file handle must be created with the GENERIC_WRITE access right. For more information, see File Security and Access Rights.

    Return value

    If the function succeeds, the return value is nonzero.

    If the function fails, the return value is zero (0). To get extended error information, call GetLastError.

    Remarks

    The SetEndOfFile function can be used to truncate or extend a file. If the file is extended, the contents of the file between the old end of the file and the new end of the file are not defined.

    Each file stream has the following:

    • File size: the size of the data in a file, to the byte.
    • Allocation size: the size of the space that is allocated for a file on a disk, which is always an even multiple of the cluster size.
    • Valid data length: the length of the data in a file that is actually written, to the byte. This value is always less than or equal to the file size.

    The SetEndOfFile function sets the file size. Use SetFileValidData to set the valid data length.

    If
    CreateFileMapping is called to create a file mapping object for hFile, UnmapViewOfFile must be called first to unmap all views and call CloseHandle to close the file mapping object before you can call SetEndOfFile.

    Transacted Operations

    In WindowsВ 8 and Windows ServerВ 2012, this function is supported by the following technologies.

    SetFilePointer function (fileapi.h)

    Moves the file pointer of the specified file.

    This function stores the file pointer in two LONG values. To work with file pointers that are larger than a single LONG value, it is easier to use the SetFilePointerEx function.

    Syntax

    Parameters

    A handle to the file.

    The file handle must be created with the GENERIC_READ or GENERIC_WRITE access right. For more information, see File Security and Access Rights.

    The low order 32-bits of a signed value that specifies the number of bytes to move the file pointer.

    If lpDistanceToMoveHigh is not NULL, lpDistanceToMoveHigh and lDistanceToMove form a single 64-bit signed value that specifies the distance to move.

    If lpDistanceToMoveHigh is NULL, lDistanceToMove is a 32-bit signed value. A positive value for lDistanceToMove moves the file pointer forward in the file, and a negative value moves the file pointer back.

    A pointer to the high order 32-bits of the signed 64-bit distance to move.

    If you do not need the high order 32-bits, this pointer must be set to NULL.

    When not NULL, this parameter also receives the high order DWORD of the new value of the file pointer. For more information, see the Remarks section in this topic.

    The starting point for the file pointer move.

    This parameter can be one of the following values.

    Value Meaning
    FILE_BEGIN 0 The starting point is zero or the beginning of the file.
    FILE_CURRENT 1 The starting point is the current value of the file pointer.
    FILE_END 2 The starting point is the current end-of-file position.

    Return value

    If the function succeeds and lpDistanceToMoveHigh is NULL, the return value is the low-order DWORD of the new file pointer. NoteВ В If the function returns a value other than INVALID_SET_FILE_POINTER, the call to SetFilePointer has succeeded. You do not need to call GetLastError.

    If function succeeds and lpDistanceToMoveHigh is not NULL, the return value is the low-order DWORD of the new file pointer and lpDistanceToMoveHigh contains the high order DWORD of the new file pointer.

    If the function fails, the return value is INVALID_SET_FILE_POINTER. To get extended error information, call GetLastError.

    If a new file pointer is a negative value, the function fails, the file pointer is not moved, and the code returned by GetLastError is ERROR_NEGATIVE_SEEK.

    If lpDistanceToMoveHigh is NULL and the new file position does not fit in a 32-bit value, the function fails and returns INVALID_SET_FILE_POINTER.

    Remarks

    The file pointer that is identified by the value of the hFile parameter is not used for overlapped read and write operations.

    The hFile parameter must refer to a file stored on a seeking device; for example, a disk volume. Calling the SetFilePointer function with a handle to a non-seeking device such as a pipe or a communications device is not supported, even though the SetFilePointer function may not return an error. The behavior of the SetFilePointer function in this case is undefined.

    To specify the offset for overlapped operations

    • Use the Offset and OffsetHigh members of the OVERLAPPED structure.

    To determine the file type for hFile

    • Use the GetFileType function.

    For information about how to determine the position of a file pointer, see Positioning a File Pointer.

    Be careful when you set a file pointer in a multithreaded application. You must synchronize access to shared resources. For example, an application with threads that share a file handle, update the file pointer, and read from the file must protect this sequence by using a critical section object or mutex object. For more information, see Critical Section Objects and Mutex Objects.

    If the hFile handle is opened with the FILE_FLAG_NO_BUFFERING flag set, an application can move the file pointer only to sector-aligned positions. A sector-aligned position is a position that is a whole number multiple of the volume sector size. An application can obtain a volume sector size by calling the GetDiskFreeSpace function.

    If an application calls SetFilePointer with distance to move values that result in a position not sector-aligned and a handle that is opened with FILE_FLAG_NO_BUFFERING, the function fails, and GetLastError returns ERROR_INVALID_PARAMETER.

    It is not an error to set a file pointer to a position beyond the end of the file. The size of the file does not increase until you call the SetEndOfFile, WriteFile, or WriteFileEx function. A write operation increases the size of the file to the file pointer position plus the size of the buffer written, which results in the intervening bytes uninitialized.

    If the return value is INVALID_SET_FILE_POINTER and if lpDistanceToMoveHigh is non-NULL, an application must call GetLastError to determine whether or not the function has succeeded or failed. The following code example shows you that scenario.

    Although the parameter lpDistanceToMoveHigh is used to manipulate huge files, the value of the parameter should be set when moving files of any size. If it is set to NULL, then lDistanceToMove has a maximum value of 2^31–2, or 2 gigabytes less 2, because all file pointer values are signed values. Therefore, if there is even a small chance for the file to increase to that size, it is best to treat the file as a huge file and work with 64-bit file pointers. With file compression on the NTFS file system, and sparse files, it is possible to have files that are large even if the underlying volume is not very large.

    If lpDistanceToMoveHigh is not NULL, then lpDistanceToMoveHigh and lDistanceToMove form a single 64-bit signed value. The lDistanceToMove parameter is treated as the low-order 32 bits of the value, and lpDistanceToMoveHigh as the high-order 32 bits, which means that lpDistanceToMoveHigh is a sign extension of lDistanceToMove.

    To move the file pointer from zero to 2 gigabytes, lpDistanceToMoveHigh must be set to either NULL or a sign extension of lDistanceToMove. To move the pointer more than 2 gigabytes, use lpDistanceToMoveHigh and lDistanceToMove as a single 64-bit quantity. For example, to move in the range from 2 gigabytes to 4 gigabytes set the contents of lpDistanceToMoveHigh to zero, or to –1 for a negative sign extension of lDistanceToMove.

    To work with 64-bit file pointers, you can declare a LONG, treat it as the upper half of the 64-bit file pointer, and pass its address in lpDistanceToMoveHigh. This means that you have to treat two different variables as a logical unit, which can cause an error. It is best to use the LARGE_INTEGER structure to create a 64-bit value and pass the two 32-bit values by using the appropriate elements of the union.

    Also, it is best to use a function to hide the interface to SetFilePointer. The following code example shows you that scenario.

    You can use SetFilePointer to determine the length of a file. To do this, use FILE_END for dwMoveMethod and seek to location zero. The file offset returned is the length of the file. However, this practice can have unintended side effects, for example, failure to save the current file pointer so that the program can return to that location. It is best to use GetFileSize instead.

    You can also use the SetFilePointer function to query the current file pointer position. To do this, specify a move method of FILE_CURRENT and a distance of zero.

    In WindowsВ 8 and Windows ServerВ 2012, this function is supported by the following technologies.

    Technology Supported
    Server Message Block (SMB) 3.0 protocol Yes
    SMB 3.0 Transparent Failover (TFO) Yes
    SMB 3.0 with Scale-out File Shares (SO) Yes
    Cluster Shared Volume File System (CsvFS) Yes
    Resilient File System (ReFS) Yes

    В

    Examples

    For a code example of appending files, see Appending One File to Another File.

    Читайте также:  Минусы операционной системы windows phone
    Оцените статью