使用 .net 从戴尔计算机获取服务标签?

发布于 2024-08-07 07:12:42 字数 3561 浏览 3 评论 0原文

我有一个提取模型信息(硬件信息)的类 本地机器代码如下所示:

   Imports System.Management

Public Class clsWMI
    Private objOS As ManagementObjectSearcher
    Private objCS As ManagementObjectSearcher
    Private objMgmt As ManagementObject
    Private m_strComputerName As String
    Private m_strManufacturer As String
    Private m_StrModel As String
    Private m_strOSName As String
    Private m_strOSVersion As String
    Private m_strSystemType As String
    Private m_strTPM As String
    Private m_strWindowsDir As String


    Public Sub New()

        objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
        objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")
        For Each objMgmt In objOS.Get


            m_strOSName = objMgmt("name").ToString()
            m_strOSVersion = objMgmt("version").ToString()
            m_strComputerName = objMgmt("csname").ToString()
            m_strWindowsDir = objMgmt("windowsdirectory").ToString()
        Next

        For Each objMgmt In objCS.Get
            m_strManufacturer = objMgmt("manufacturer").ToString()
            m_StrModel = objMgmt("model").ToString()
            m_strSystemType = objMgmt("systemtype").ToString
            m_strTPM = objMgmt("totalphysicalmemory").ToString()
        Next
    End Sub

    Public ReadOnly Property ComputerName()
        Get
            ComputerName = m_strComputerName
        End Get

    End Property
    Public ReadOnly Property Manufacturer()
        Get
            Manufacturer = m_strManufacturer
        End Get

    End Property
    Public ReadOnly Property Model()
        Get
            Model = m_StrModel
        End Get

    End Property
    Public ReadOnly Property OsName()
        Get
            OsName = m_strOSName
        End Get

    End Property

    Public ReadOnly Property OSVersion()
        Get
            OSVersion = m_strOSVersion
        End Get

    End Property
    Public ReadOnly Property SystemType()
        Get
            SystemType = m_strSystemType
        End Get

    End Property
    Public ReadOnly Property TotalPhysicalMemory()
        Get
            TotalPhysicalMemory = m_strTPM
        End Get

    End Property

    Public ReadOnly Property WindowsDirectory()
        Get
            WindowsDirectory = m_strWindowsDir
        End Get

    End Property

End Class

有可能从 WMI 获取服务标签吗?从客户端表单中,我显示如下值:

   Dim objWMI As New clsWMI()
        With objWMI
            Debug.WriteLine("Computer Name = " & .ComputerName)
            Me.Label1.Text = "Name: " & .ComputerName
            Debug.WriteLine("Computer Manufacturer = " & .Manufacturer)
            Me.Label2.Text = "Manufacturer: " & .Manufacturer
            Debug.WriteLine("Computer Model = " & .Model)
            Me.Label3.Text = "Model: " & .Model
            Debug.WriteLine("OS Name = " & .OsName)
            Me.Label4.Text = "OS Name: " & .OsName
            Debug.WriteLine("OS Version = " & .OSVersion)
            Me.Label5.Text = "OS VERSION: " & .OSVersion

            Debug.WriteLine("System Type = " & .SystemType)
            Me.Label6.Text = "System type = " & .SystemType

            Debug.WriteLine("Total Physical Memory = " & .TotalPhysicalMemory)
            Me.Label7.Text = "Memory: " & .TotalPhysicalMemory
            Debug.WriteLine("Windows Directory = " & .WindowsDirectory)
            Me.Label8.Text = "Win Directory: " & .WindowsDirectory
        End With

I've got a class that pulls model information (hardware info)
for a local machine code is like so:

   Imports System.Management

Public Class clsWMI
    Private objOS As ManagementObjectSearcher
    Private objCS As ManagementObjectSearcher
    Private objMgmt As ManagementObject
    Private m_strComputerName As String
    Private m_strManufacturer As String
    Private m_StrModel As String
    Private m_strOSName As String
    Private m_strOSVersion As String
    Private m_strSystemType As String
    Private m_strTPM As String
    Private m_strWindowsDir As String


    Public Sub New()

        objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
        objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")
        For Each objMgmt In objOS.Get


            m_strOSName = objMgmt("name").ToString()
            m_strOSVersion = objMgmt("version").ToString()
            m_strComputerName = objMgmt("csname").ToString()
            m_strWindowsDir = objMgmt("windowsdirectory").ToString()
        Next

        For Each objMgmt In objCS.Get
            m_strManufacturer = objMgmt("manufacturer").ToString()
            m_StrModel = objMgmt("model").ToString()
            m_strSystemType = objMgmt("systemtype").ToString
            m_strTPM = objMgmt("totalphysicalmemory").ToString()
        Next
    End Sub

    Public ReadOnly Property ComputerName()
        Get
            ComputerName = m_strComputerName
        End Get

    End Property
    Public ReadOnly Property Manufacturer()
        Get
            Manufacturer = m_strManufacturer
        End Get

    End Property
    Public ReadOnly Property Model()
        Get
            Model = m_StrModel
        End Get

    End Property
    Public ReadOnly Property OsName()
        Get
            OsName = m_strOSName
        End Get

    End Property

    Public ReadOnly Property OSVersion()
        Get
            OSVersion = m_strOSVersion
        End Get

    End Property
    Public ReadOnly Property SystemType()
        Get
            SystemType = m_strSystemType
        End Get

    End Property
    Public ReadOnly Property TotalPhysicalMemory()
        Get
            TotalPhysicalMemory = m_strTPM
        End Get

    End Property

    Public ReadOnly Property WindowsDirectory()
        Get
            WindowsDirectory = m_strWindowsDir
        End Get

    End Property

End Class

Any possibility to get a service tag from WMI ? From the client side form I display values like so:

   Dim objWMI As New clsWMI()
        With objWMI
            Debug.WriteLine("Computer Name = " & .ComputerName)
            Me.Label1.Text = "Name: " & .ComputerName
            Debug.WriteLine("Computer Manufacturer = " & .Manufacturer)
            Me.Label2.Text = "Manufacturer: " & .Manufacturer
            Debug.WriteLine("Computer Model = " & .Model)
            Me.Label3.Text = "Model: " & .Model
            Debug.WriteLine("OS Name = " & .OsName)
            Me.Label4.Text = "OS Name: " & .OsName
            Debug.WriteLine("OS Version = " & .OSVersion)
            Me.Label5.Text = "OS VERSION: " & .OSVersion

            Debug.WriteLine("System Type = " & .SystemType)
            Me.Label6.Text = "System type = " & .SystemType

            Debug.WriteLine("Total Physical Memory = " & .TotalPhysicalMemory)
            Me.Label7.Text = "Memory: " & .TotalPhysicalMemory
            Debug.WriteLine("Windows Directory = " & .WindowsDirectory)
            Me.Label8.Text = "Win Directory: " & .WindowsDirectory
        End With

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

忆梦 2024-08-14 07:12:42

我认为您需要从 BIOS 中获取序列号,如下所示:

Select SerialNumber From Win32_BIOS

在戴尔上,我相信这对应于服务标签

I think you need to get the serial number from the BIOS like this:

Select SerialNumber From Win32_BIOS

On Dell's I believe this corresponds to the service tag

蓝海 2024-08-14 07:12:42

这是一些应该得到它的 C# 代码,

我从 获取Win32_ComputerSystem 但如果您愿意,可以轻松地将其转换为再次运行 Win32_Bios

void GetComputerSystem()
{
        // http://msdn.microsoft.com/en-us/library/aa394102(VS.85).aspx
        ManagementObjectCollection oReturnCollection;
        try
        {
            ObjectQuery query = new ObjectQuery("Select UserName,Name,Manufacturer,Model from Win32_ComputerSystem");
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(gManager, query);
            oReturnCollection = oSearcher.Get();
            oSearcher.Dispose();
        }
        catch
        {
            gHasError = true;
            return;
        }

        //loop through found drives and write out info
        foreach (ManagementObject oReturn in oReturnCollection)
        {
        // Disk name  
            object oLoggedInUser = oReturn["UserName"];
            if (oLoggedInUser == null)
                gOSInfo.UserName = "None";
            else
                gOSInfo.UserName = (string)oLoggedInUser;

            string Manufacturer = (string)oReturn["Manufacturer"];
            string Model = (string)oReturn["Model"];
        }
    }
}

Here is some C# code that should get it

Here im getting from Win32_ComputerSystem but if you desire you can easly convert it to run againt Win32_Bios

void GetComputerSystem()
{
        // http://msdn.microsoft.com/en-us/library/aa394102(VS.85).aspx
        ManagementObjectCollection oReturnCollection;
        try
        {
            ObjectQuery query = new ObjectQuery("Select UserName,Name,Manufacturer,Model from Win32_ComputerSystem");
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(gManager, query);
            oReturnCollection = oSearcher.Get();
            oSearcher.Dispose();
        }
        catch
        {
            gHasError = true;
            return;
        }

        //loop through found drives and write out info
        foreach (ManagementObject oReturn in oReturnCollection)
        {
        // Disk name  
            object oLoggedInUser = oReturn["UserName"];
            if (oLoggedInUser == null)
                gOSInfo.UserName = "None";
            else
                gOSInfo.UserName = (string)oLoggedInUser;

            string Manufacturer = (string)oReturn["Manufacturer"];
            string Model = (string)oReturn["Model"];
        }
    }
}
猥琐帝 2024-08-14 07:12:42

我编写了一个程序,用于恢复戴尔服务标签、快速代码以及驱动程序和保修信息的链接。 找到 C# 代码

您可以在http://samuelhaddad.com/software-projects/dellservicetagfinder/

我希望这对其他人有帮助。

I wrote a program the recovers the Dell Service Tag, Express Code and links to the Driver and Warranty information. You can find the C# code at

http://samuelhaddad.com/software-projects/dellservicetagfinder/

I hope this helps others.

茶底世界 2024-08-14 07:12:42
namespace Con2
{
    using System;
    using System.Management;
    using System.IO;

    class Program
    {
        public static string computerName = "localhost";

        // a central place to store the info, 
        public static string inventFile = @"\\Wdstorage\public\install\Inventfile.txt";

        static void Main(string[] args)
        {
            try
            {
                FileStream fileStream = new FileStream(inventFile, FileMode.Append);

                if (File.Exists(inventFile))
                {
                    using (StreamWriter sw = new StreamWriter(fileStream))
                    {
                        sw.Write("Added: " + DateTime.Now.ToString());

                        ManagementScope scope = new ManagementScope(@"\\" + computerName + @"\root\cimv2");
                        scope.Connect();

                        ObjectQuery query = new ObjectQuery("Select * From Win32_SystemEnclosure");
                        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
                        ManagementObjectCollection objColl = searcher.Get();

                        foreach (ManagementObject o in objColl)
                        {
                            Console.WriteLine("ServiceTag=" + o["SerialNumber"].ToString());
                            sw.Write(",  ServiceTag=" + o["SerialNumber"].ToString());
                        }

                        query = new ObjectQuery("Select * from Win32_ComputerSystem");
                        searcher = new ManagementObjectSearcher(scope, query);

                        objColl = searcher.Get();

                        foreach (ManagementObject oReturn in objColl)
                        {
                            string Manufacturer = (string)oReturn["Manufacturer"];
                            sw.Write(", Manufacturer=" + (string)oReturn["Manufacturer"]);

                            string Model = (string)oReturn["Model"];
                            sw.Write(", Model=" + (string)oReturn["Model"]);

                            string name = (string)oReturn["Name"];
                            sw.Write(", name=" + (string)oReturn["name"]);

                            string userName = (string)oReturn["UserName"];
                            sw.Write(", userName=" + (string)oReturn["userName"]);

                            Console.WriteLine((string)oReturn["Manufacturer"]);
                            Console.WriteLine((string)oReturn["Model"]);
                            Console.WriteLine((string)oReturn["Name"]);
                            Console.WriteLine((string)oReturn["UserName"]);

                        }
                        sw.WriteLine();
                        sw.Close();
                    }
                }
                // else 
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error :" + ex.Message );
                Console.WriteLine("Prova att köra programmet en gång till..");
            }

            Console.WriteLine("");
            Console.Write("<Enter> to quit :");
            Console.ReadLine();
        }
    }
}
namespace Con2
{
    using System;
    using System.Management;
    using System.IO;

    class Program
    {
        public static string computerName = "localhost";

        // a central place to store the info, 
        public static string inventFile = @"\\Wdstorage\public\install\Inventfile.txt";

        static void Main(string[] args)
        {
            try
            {
                FileStream fileStream = new FileStream(inventFile, FileMode.Append);

                if (File.Exists(inventFile))
                {
                    using (StreamWriter sw = new StreamWriter(fileStream))
                    {
                        sw.Write("Added: " + DateTime.Now.ToString());

                        ManagementScope scope = new ManagementScope(@"\\" + computerName + @"\root\cimv2");
                        scope.Connect();

                        ObjectQuery query = new ObjectQuery("Select * From Win32_SystemEnclosure");
                        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
                        ManagementObjectCollection objColl = searcher.Get();

                        foreach (ManagementObject o in objColl)
                        {
                            Console.WriteLine("ServiceTag=" + o["SerialNumber"].ToString());
                            sw.Write(",  ServiceTag=" + o["SerialNumber"].ToString());
                        }

                        query = new ObjectQuery("Select * from Win32_ComputerSystem");
                        searcher = new ManagementObjectSearcher(scope, query);

                        objColl = searcher.Get();

                        foreach (ManagementObject oReturn in objColl)
                        {
                            string Manufacturer = (string)oReturn["Manufacturer"];
                            sw.Write(", Manufacturer=" + (string)oReturn["Manufacturer"]);

                            string Model = (string)oReturn["Model"];
                            sw.Write(", Model=" + (string)oReturn["Model"]);

                            string name = (string)oReturn["Name"];
                            sw.Write(", name=" + (string)oReturn["name"]);

                            string userName = (string)oReturn["UserName"];
                            sw.Write(", userName=" + (string)oReturn["userName"]);

                            Console.WriteLine((string)oReturn["Manufacturer"]);
                            Console.WriteLine((string)oReturn["Model"]);
                            Console.WriteLine((string)oReturn["Name"]);
                            Console.WriteLine((string)oReturn["UserName"]);

                        }
                        sw.WriteLine();
                        sw.Close();
                    }
                }
                // else 
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error :" + ex.Message );
                Console.WriteLine("Prova att köra programmet en gång till..");
            }

            Console.WriteLine("");
            Console.Write("<Enter> to quit :");
            Console.ReadLine();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文