Feedback

C# - Name der Windows-Workgroup auslesen

Veröffentlicht von am 8/28/2008
(1 Bewertungen)
Gibt den Namen der Windows Workgroup aus, in der sich der Computer befindet
        /// <summary>
        /// Returns the name of the workgroup when the computer is member of a workgroup.
        /// Throws an exception if the computer is a member of a domain.
        /// </summary>
        /// <returns>Returns he full name of the workgroup</returns>
        public static string GetWorkgroupName()
        {
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
                foreach( ManagementObject queryObj in searcher.Get() )
                {
                    return queryObj["Workgroup"].ToString();
                }
            } catch( Exception e )
            {
                throw new ManagementException("Error retrieving workgroup name.", e);
            }
            throw new ManagementException("Error retrieving workgroup name.");
        }
Abgelegt unter Workgroup, Arbeitsgruppe.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!