4
4

More than 3 years have passed since last update.

【UiPath】実行マシンの情報を取得する(スペック)

Last updated at Posted at 2021-07-23

はじめに

この投稿は、RPAツール「UiPath」での 実装例 について記事です。

UiPathのコミュニティ「UiPath Friends」が企画する「UiPathブログ発信チャレンジ2021サマー」の 23日目の投稿でもあります。

企画の内容は こちら 。カレンダーのURLは こちら です。

実行マシンの情報を取得するシリーズ

同様の内容で以下の投稿もあります。参考まで

マシンのスペックが知りたいとき

ロボットの実行が上手く行かなかったり、スペックが異常に低いマシンがある場合は、CPUやメモリ等のマシンスペックが知りたくなります。

マシンスペックは「msinfo32」や「dxdiag」で取得するのが有名ですが、同様の情報をUiPathで一覧取得したいと思います。

.NETで取得する

標準アクティビティで「マシンスペックを取得」アクティビティ みたいなのがあれば良いのですが、現時点では無いみたいです。

なので、以下に VB.NET で取得するコードを用意しました。(持ち出しやすいように、匿名変数型にしています)

func =
    Function() As Dictionary(Of String, Object)
        Dim dic As New Dictionary(Of String, Object)
        Dim ComputerInfo As New Microsoft.VisualBasic.Devices.ComputerInfo()
        dic("MachineName") = System.Environment.MachineName
        dic("OSFullName") = ComputerInfo.OSFullName
        dic("OSVersion") = CType(New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").get()(0),System.Management.ManagementObject).Item("Version").ToString
        dic("Is64BitOperatingSystem") = System.Environment.Is64BitOperatingSystem
        dic("ProcessorName") = CType(New ManagementObjectSearcher("SELECT * FROM Win32_Processor").get()(0),System.Management.ManagementObject).Item("Name").ToString
        dic("ProcessorCount") = System.Environment.ProcessorCount
        dic("TotalPhysicalMemory") = Math.Round(ComputerInfo.TotalPhysicalMemory / 1024 /1024 / 1024).ToString + "GB"
        dic("AvailablePhysicalMemory") = Math.Round(ComputerInfo.AvailablePhysicalMemory / 1024 /1024 / 1024).ToString + "GB"
        dic("InstalledUICulture") = ComputerInfo.InstalledUICulture.DisplayName
        dic("TimeZoneInfo") = System.TimeZoneInfo.Local.DisplayName
        dic("ProductVendor") = CType(New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystemProduct").get()(0),System.Management.ManagementObject).Item("Vendor").ToString
        dic("ProductName") = CType(New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystemProduct").get()(0),System.Management.ManagementObject).Item("Name").ToString
        dic("FrameworkDescription") = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription        
        dic("PrimaryScreenHeight") = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
        dic("PrimaryScreenWidth") = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
        Return dic
    End Function

簡単には取れないので、いろいろな所から欲しい情報を集めてきています。
これを、こんな感じのフローで実行すると

image.png

以下のように出力されます。
67aaaab.png

確認しやすいように、以下でxamlを公開しています。

終わりに

いかがでしたでしょうか?実装の参考になれば幸いです。

この記事が参考になったら、 LGTMをお願いします。閲覧ありがとうございました。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4