1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

workgroup名の取得方法

Last updated at Posted at 2019-12-18

.Net C#でworkgroup名を取得する方法です。
日本語でググると Marshal を利用した方法がトップに出るのですが、Windows10では保護されたメモリ領域へのアクセスとして例外エラーが生じます。

以下からの引用の一部改変(usingなしでOKな記述に変更)ですが、載せておきます。
https://stackoverflow.com/questions/2708610/how-can-i-get-the-workgroup-name-of-a-computer-using-c

        public static string GetWorkGroupName()
        {
            System.Management.ManagementObject computer_system = new System.Management.ManagementObject(
                        string.Format(
                        "Win32_ComputerSystem.Name='{0}'",
                        Environment.MachineName));

            object result = computer_system["Workgroup"];
            return result.ToString();
        }
1
0
1

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?