Jump to content

Code for creating the Page File...


Recommended Posts

Hi,

Could anyone help me translate the code below to AutoItv3?

Here is the code for creating the page file in C++:

static BOOL EnablePrivilege()
{
    HANDLE hToken;
    TOKEN_PRIVILEGES tp;

    // Get a token for this process.
    OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
    // Get the LUID for the shutdown privilege.
    LookupPrivilegeValue(NULL, SE_CREATE_PAGEFILE_NAME, &tp.Privileges[0].Luid);

    tp.PrivilegeCount = 1;
    tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

    AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, 0);
    DWORD ret = GetLastError();
    return ret == ERROR_SUCCESS;
}



...

    HMODULE hDLL = LoadLibrary("NTDLL.dll");
    NtCreatePagingFile pf = (NtCreatePagingFile)GetProcAddress(hDLL, "NtCreatePagingFile");
    if (!EnablePrivilege())
    {
        return 1;
    }

        WCHAR pagefile[MAX_PATH];
    TCHAR Disk[25];
    TCHAR Dir = FileName[2];

    FileName[2] = 0;
    QueryDosDevice(FileName, Disk, 25);
    FileName[2]=Dir;

    StringCbPrintfW(pagefile, MAX_PATH, L"%S\\%S",Disk, &FileName[3]);
    int len = lstrlenW(pagefile);

    ULARGE_INTEGER liMinSize;
    ULARGE_INTEGER liMaxSize;
    liMinSize.QuadPart = MinSize;
    liMaxSize.QuadPart = MaxSize;
    liMinSize.QuadPart *= (1024 * 1024);
    liMaxSize.QuadPart *= (1024 * 1024);

    UNICODE_STRING us;
    us.Buffer = pagefile;
    us.Length = (USHORT)(len*sizeof(WCHAR));
    us.MaximumLength = us.Length+sizeof(WCHAR);
    DWORD ret = pf(&us, &liMinSize, &liMaxSize, 0);

Source: Enabling page file on the LiveXP after boot

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...