.NET/WMIを使って物理メモリ・仮想メモリの使用量等を取得する
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* WMIを使って物理メモリ・仮想メモリの使用量等を取得する [...
WMIを使ってWMI ClassのWin32_OperatingSystemからメモリの使...
尚、コンソールアプリケーションを動かすには参照にて''Syste...
#contents
* 動作確認環境 [#o8a46bf7]
- Windows 10 ver.1909
- Visual Studio 2019
- .NET Framework 4.7.2
- コンソールアプリケーション
#htmlinsert(windev-top.html)
* 関連記事 [#l053efca]
-[[CPU使用率を取得するサンプルコード>.NET/CPU使用率を取得...
-[[CPUコア毎の使用率を取得するサンプルコード>.NET/CPUコア...
* 関連サイト [#kdaa7289]
-[[Microsoft .NET ManagementClass クラス>https://docs.mic...
* 参照追加 [#u59cbf8d]
''System.Management''を参照に追加しないと以下のように&col...
#ref(11.png)
#br
** ''System.Management''の参照追加手順 [#xaab5e4a]
''System.Management''を参照追加するにあたり、以下の手順で...
+ 参照を右クリック
#ref(01.png)
#br
+ 参照マネージャーが表示されるので「アセンブリ」になって...
検索ボックスに''System.Management''を入力します。
+ チェックを入れ「OK」ボタンをクリックします。
#ref(02.png)
#br
+以上の操作で''System.Management''の参照追加は完了です。
* サンプルコード [#z925f522]
以下に C#, Visual Basic(VB) のサンプルコードと実行結果を...
** C# サンプルコード [#u3c86072]
using System;
class Program
{
static void Main(string[] args)
{
while (true)
{
using (System.Management.ManagementClass smm...
using (System.Management.ManagementObjectCol...
{
foreach (System.Management.ManagementObj...
using (smmo)
{
UInt64 TotalVisibleMemorySize = ...
UInt64 FreePhysicalMemory = (UIn...
UInt64 TotalVirtualMemorySize = ...
UInt64 FreeVirtualMemory = (UInt...
Console.WriteLine("合計物理メモ...
TotalVisibleMemorySize,
TotalVisibleMemorySize / 102...
TotalVisibleMemorySize / 102...
);
Console.WriteLine("利用可能物理...
FreePhysicalMemory,
FreePhysicalMemory / 1024f,
FreePhysicalMemory / 1024f /...
);
Console.WriteLine("合計仮想メモ...
TotalVirtualMemorySize,
TotalVirtualMemorySize / 102...
TotalVirtualMemorySize / 102...
);
Console.WriteLine("利用可能仮想...
FreeVirtualMemory,
FreeVirtualMemory / 1024f,
FreeVirtualMemory / 1024f / ...
);
}
}
System.Threading.Thread.Sleep(1000);
Console.Clear();
}
}
}
** Visual Basic(VB) サンプルコード [#nca661cb]
Module Module1
Sub Main()
While True
Using smmc As System.Management.ManagementCl...
Using smc As System.Management.Managemen...
For Each smmo As System.Management.M...
Using smmo
Dim TotalVisibleMemorySize A...
Dim FreePhysicalMemory As UI...
Dim TotalVirtualMemorySize A...
Dim FreeVirtualMemory As UIn...
Console.WriteLine("合計物理...
Console.WriteLine("利用可能...
Console.WriteLine("合計仮想...
Console.WriteLine("利用可能...
End Using
Next
End Using
End Using
System.Threading.Thread.Sleep(1000)
Console.Clear()
End While
End Sub
End Module
** 実行結果 [#v856fd7b]
上記サンプルコードの実行結果(キャプチャ)になります。~
#ref(12.png)
以上、WMIを使ってメモリの使用量等を取得するサンプルコード...
#htmlinsert(windev-btm.html)
終了行:
#navi(../)
* WMIを使って物理メモリ・仮想メモリの使用量等を取得する [...
WMIを使ってWMI ClassのWin32_OperatingSystemからメモリの使...
尚、コンソールアプリケーションを動かすには参照にて''Syste...
#contents
* 動作確認環境 [#o8a46bf7]
- Windows 10 ver.1909
- Visual Studio 2019
- .NET Framework 4.7.2
- コンソールアプリケーション
#htmlinsert(windev-top.html)
* 関連記事 [#l053efca]
-[[CPU使用率を取得するサンプルコード>.NET/CPU使用率を取得...
-[[CPUコア毎の使用率を取得するサンプルコード>.NET/CPUコア...
* 関連サイト [#kdaa7289]
-[[Microsoft .NET ManagementClass クラス>https://docs.mic...
* 参照追加 [#u59cbf8d]
''System.Management''を参照に追加しないと以下のように&col...
#ref(11.png)
#br
** ''System.Management''の参照追加手順 [#xaab5e4a]
''System.Management''を参照追加するにあたり、以下の手順で...
+ 参照を右クリック
#ref(01.png)
#br
+ 参照マネージャーが表示されるので「アセンブリ」になって...
検索ボックスに''System.Management''を入力します。
+ チェックを入れ「OK」ボタンをクリックします。
#ref(02.png)
#br
+以上の操作で''System.Management''の参照追加は完了です。
* サンプルコード [#z925f522]
以下に C#, Visual Basic(VB) のサンプルコードと実行結果を...
** C# サンプルコード [#u3c86072]
using System;
class Program
{
static void Main(string[] args)
{
while (true)
{
using (System.Management.ManagementClass smm...
using (System.Management.ManagementObjectCol...
{
foreach (System.Management.ManagementObj...
using (smmo)
{
UInt64 TotalVisibleMemorySize = ...
UInt64 FreePhysicalMemory = (UIn...
UInt64 TotalVirtualMemorySize = ...
UInt64 FreeVirtualMemory = (UInt...
Console.WriteLine("合計物理メモ...
TotalVisibleMemorySize,
TotalVisibleMemorySize / 102...
TotalVisibleMemorySize / 102...
);
Console.WriteLine("利用可能物理...
FreePhysicalMemory,
FreePhysicalMemory / 1024f,
FreePhysicalMemory / 1024f /...
);
Console.WriteLine("合計仮想メモ...
TotalVirtualMemorySize,
TotalVirtualMemorySize / 102...
TotalVirtualMemorySize / 102...
);
Console.WriteLine("利用可能仮想...
FreeVirtualMemory,
FreeVirtualMemory / 1024f,
FreeVirtualMemory / 1024f / ...
);
}
}
System.Threading.Thread.Sleep(1000);
Console.Clear();
}
}
}
** Visual Basic(VB) サンプルコード [#nca661cb]
Module Module1
Sub Main()
While True
Using smmc As System.Management.ManagementCl...
Using smc As System.Management.Managemen...
For Each smmo As System.Management.M...
Using smmo
Dim TotalVisibleMemorySize A...
Dim FreePhysicalMemory As UI...
Dim TotalVirtualMemorySize A...
Dim FreeVirtualMemory As UIn...
Console.WriteLine("合計物理...
Console.WriteLine("利用可能...
Console.WriteLine("合計仮想...
Console.WriteLine("利用可能...
End Using
Next
End Using
End Using
System.Threading.Thread.Sleep(1000)
Console.Clear()
End While
End Sub
End Module
** 実行結果 [#v856fd7b]
上記サンプルコードの実行結果(キャプチャ)になります。~
#ref(12.png)
以上、WMIを使ってメモリの使用量等を取得するサンプルコード...
#htmlinsert(windev-btm.html)
ページ名: