Using the DRY principle would make your second option the better one (Ignoring the lack of SQL parameters in this instance). Its less code to write and would be easy to maintain. However it could lead to a bug if the developer fixing the code didn't know all the places that called this function.
I would lean to having the single private method and then calling that from the public methods.
public class Win32OperatingSystem
{
internal ulong BytesToMegaBytes(ulong bytes)
{
return bytes / (ulong)1024;
}
public ulong FreePhysicalMemory()
{
return GetProperty("FreePhysicalMemory");
}
public ulong TotalVirtualMemorySize()
{
return GetProperty("TotalVirtualMemorySize");
}
public ulong FreeVirtualMemory()
{
return GetProperty("FreeVirtualMemory");
}
private ulong GetProperty(string propertyName)
{
ManagementObjectSearcher moSearcher = new ManagementObjectSearcher
("SELECT " + propertyName + " FROM Win32_OperatingSystem");
using (var enu = moSearcher.Get().GetEnumerator())
{
if (!enu.MoveNext()) return 0;
return BytesToMegaBytes((ulong)enu.Current[propertyName]);
}
}
}