|
Actually, it works fine if you add up all of the Win32_PhysicalMemory objects that are returned:
const long BytesToMBConversion = 1048576;
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory");
long totalMemSize = 0;
foreach (ManagementObject item in searcher.Get)
{
long currentMemSize = Convert.ToInt64(item("Capacity"));
totalMemSize += currentMemSize;
Console.WriteLine("Memory Size: {0} MB", currentMemSize / BytesToMBConversion);
}
Console.WriteLine("Total memory size: {0} MB", totalMemSize / BytesToMBConversion);
|
|
|
|
|
Download the WMI Code Creator:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e&displaylang=en
It lists all WMI classes and you can quick get the values you are wanting. Not only this but you can choose to display/use the code in various different languages. It is a very useful tool when messing with WMI.
Oh btw it says it doesn't support Windows 7 but I use it on Windows 7 without any issues so far.
|
|
|
|
|
This is what I use, based on a Win32 function and P/Invoke:
public static long GetPhysicalRAMSize() {
MEMORYSTATUSEX ms=new MEMORYSTATUSEX();
ms.Length=64;
GlobalMemoryStatusEx(ref ms);
long RAM=ms.TotalPhys;
RAM=(RAM+0x000FFFFF)&0x7FFFFFFFFFF00000L;
return RAM;
}
[DllImport("kernel32.dll")]
public static extern void GlobalMemoryStatusEx(ref MEMORYSTATUSEX ms);
public struct MEMORYSTATUSEX {
public int Length;
public int MemoryLoad;
public long TotalPhys;
public long AvailPhys;
public long TotalPageFile;
public long AvailPageFile;
public long TotalVirtual;
public long AvailVirtual;
public long AvailExtendedVirtual;
}
(together with some using statements).
It reports 3070MB (out of 3072MB) on a 3GB system (Vista/32) and 3957MB (out of 4096MB) on a 4GB system (Win7/64).
|
|
|
|
|
it does exactly what i wrote before, it gets the amount of memory which is used by OS (in my case 3gb out of 4gb i have)
in other words it doesn't do requested job
|
|
|
|
|
I just checked the WMI approach you have, and it works fine for me returning about 3GB and 4GB for two different systems...
|
|
|
|
|
then why i get 2gb instead of 4 ?
another q, is how to get reference to LP_Win32.MEMORYSTATUS ?
Thanks
modified on Wednesday, November 17, 2010 4:44 AM
|
|
|
|
|
Because, as documented, Win32_ComputerSystem is unreliable. It depends on the machines BIOS to be accurate, which some are not.
Use Win32_PhysicalMemory instead. Add up the Capacity values for all of the PhysicalMemory objects returned and you'll get your total system RAM.
|
|
|
|
|
Dave Kreskowiak wrote: Use Win32_PhysicalMemory instead. Add up the Capacity values for all of the PhysicalMemory objects returned and you'll get your total system RAM.
Thanks, it worked, and I get all my 4gb
|
|
|
|
|
sorry. I copied the wrong prototype. Fixed now.
|
|
|
|
|
Hi,
I have one repeater and i am showing the data like this:
<asp:Repeater ID = "rptViewActiveCourses" runat="server" onitemdatabound="rptViewActiveCourses_ItemDataBound" >
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
<%# DataBinder.Eval(Container.DataItem,"ID") %>
<%# DataBinder.Eval(Container.DataItem, "Year") %><br />
</ItemTemplate>
</asp:Repeater>
Now what i need is for every Name , if it starts with "s", I need to show small "right mark" on the side.
So How to loop the items already in the repeater ?
suchita
|
|
|
|
|
Hi suchita,
include some place holders into your item template (a label will do for a first test) and do the
population with data from within the rptViewActiveCourses_ItemDataBound method in the code behind
file. There you can check "Name" data item and do the logic to add a mark into one of the place-
holdes where appropriate.
Enough hints? You're welcome to come back for more
Cheers
Manfred
|
|
|
|
|
thanks. it worked.
suchita
|
|
|
|
|
|
Please post your questions to the correct forum; ASP.NET is more appropriate than C# in this instance.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
|
Repost.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I am using sql2008 in my project.
In one of my tables one record in 1000 records can not be updated from sql2008 Editing enviroment (In MyTbl Edit Top 200 Row Window) and it makes error, but I can update that record from QueryAnalizer Window (With Sql Commands).
I have no problem with other records in this table.
Can anyone help me with this?
|
|
|
|
|
What error are you getting?
You might need to post some code here before anyone can help you.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
you are right but unfourtunately the computer that makes that error is not here now , So i will see the error message and ask it again to help
thanks my friend
|
|
|
|
|
Simple - what is implemented in the code is NOT the same as what you use in the window.
Common causes
- Assuming the data is the same rather than actually verifying it. If you didn't print it with deliminters then you assumed it.
- SQL syntax is slightly different.
|
|
|
|
|
i am trying to use PropertyInfo.GetValue() method to get the property value of some class..
its throuwing some target not found exception...
pls advise me the correct way..
|
|
|
|
|
inlight me!!
EASY COME EASY GO
|
|
|
|
|
arun_pk wrote: its throuwing some target not found exception..
Can you show the code where it is throwing that exception?
I are Troll
|
|
|
|
|
This exception can be thrown in two cases:
- The property is not static and you pass null to the target parameter.
- The property is not static but the object you pass as target does not match the target type.
As you say you want to "get the property value of some class" I guess your case is the first one. If a property is not static, you can get the property value of an instance of a class.
|
|
|
|
|