NEWS

[C#] Lấy thông tin cấu hình máy tính xuất ra text file winform

[C#] Lấy thông tin cấu hình máy tính xuất ra text file winform
Đăng bởi: Thảo Meo - Lượt xem: 5458 08:11:51, 25/02/2021C#   In bài viết

Xin chào các bạn, bài viết hôm nay mình sẽ chia sẽ đến các bạn class SystemInfoHelper.cs, dùng để lấy cấu hình thông tin phần cứng máy tính xuất ra text file trong lập trình c#, winform.

[C#] Get system info to text file

Kiểm tra cấu hình laptop, máy tính là việc làm cần thiết khi bạn muốn biết chính xác các phần cứng được trang bị trên máy.

Để kiểm tra thông tin cấu hình máy tính Windows bạn có thể dùng lệnh dxdiag trên cmd, xem qua Properties của PC hoặc dùng phần mềm hỗ trợ.

Trong bài viết dưới đây, mình sẽ hướng dẫn các bạn những cách kiểm tra, xem cấu hình phần cứng trên máy tính nhanh chóng, đơn giản nhất nhưng vẫn đảm bảo cung cấp đủ thông tin máy tính cần thiết, có thể thực hiện được cả trên Windows 10, 8/8.1, Windows 7, XP.

systeminfo_textfile_csharp

Với class này, các bạn sẽ dễ dàng lấy cấu hình phần cứng của máy Client xuất ra Text File, rồi có thể gởi file text này về Server chẳng hạn.

Giao diện demo ứng dụng lấy thông tin cấu hình ra Text File C#:

systeminfo_textfile

Class SystemInfoHelper.cs rất dài, nên các bạn download ở dưới source code bài viết của mình nhé.

Code Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace systeminfo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private const int WM_SYSCOMMAND = 274; private const int SC_MAXIMIZE = 61488;

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]

        public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);       
        private async void btnGetsystemInfo_Click(object sender, EventArgs e)
        {
            btnGetsystemInfo.Text = "Please waiting...";
            btnGetsystemInfo.Enabled = false;
           await SystemInfoHelper.WriteFileText("info.txt");
            ProcessStartInfo startInfo = new ProcessStartInfo("notepad.exe", "info.txt");
            startInfo.WindowStyle = ProcessWindowStyle.Maximized;
            var proc = Process.Start(startInfo);
            proc.WaitForInputIdle();
            SetParent(proc.MainWindowHandle, panel1.Handle);
            btnGetsystemInfo.Text = "Get System Info";
            btnGetsystemInfo.Enabled = true;
        }
    }
}

Thanks for watching!

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Lấy thông tin cấu hình máy tính xuất ra text file winform
Đăng bởi: Thảo Meo - Lượt xem: 5458 08:11:51, 25/02/2021C#   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.