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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing virtual memory from code 2

Status
Not open for further replies.

richrock316

Programmer
Jul 30, 2003
57
US
How can you change the virtual memory minimum and maximum using Visual Basic code?

Also how can you use code to find out how much RAM a computer has?

Thanks
 
Thanks Tom,

that would indeed work. I was able to use a api function globalmemorystatus to get it.

Still havent had any luck with an way to cange the aging file size with code.

Richard
 
Haven't tried very hard then ... ;-)

Note: you take full responsibility for what may or may not happen on your PC whenmodifying virtual memory settings:
Code:
[blue]Public Sub Experiment()
    Dim objWMIService As Object
    Dim PageFiles As Object
    Dim PageFile As Object
    Dim WriteablePageFilesInfo As Object
    Dim WriteablePageFileInfo As Object

    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\." & "\root\cimv2")
            If Err = 0 Then
                Set PageFiles = objWMIService.ExecQuery("select * from Win32_PageFileUsage")
                For Each PageFile In PageFiles
                    Set WriteablePageFilesInfo = objWMIService.ExecQuery("select * from Win32_PageFileSetting")
                    For Each WriteablePageFileInfo In WriteablePageFilesInfo
                        If PageFile.Description = WriteablePageFileInfo.Name Then
                            Debug.Print "Pagefile: " & PageFile.Description
                            Debug.Print "Allocated (Mb): " & PageFile.allocatedbasesize
                            Debug.Print "Current (Mb): " & PageFile.currentusage
                            Debug.Print "Peak (Mb): " & PageFile.peakusage
                            ' If the following are both 0 then Windows is handling pagefile size
                            Debug.Print WriteablePageFileInfo.initialsize ' we can set these instead
                            Debug.Print WriteablePageFileInfo.maximumsize ' we can set these instead
                        End If
                    Next
                Next
            End If
End Sub[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top