Skip to main content

๐Ÿ‘ฉโ€๐Ÿ’ป ๅ–ๅพ— Windows Product Id

ไฝฟ็”จๆŸฅ่ฉข Win32_OperatingSystem ้กžๅˆฅ๏ผŒ

็„ถๅพŒ็ฒๅ–ๆ“ไฝœ็ณป็ตฑ็š„็”ขๅ“่ญ˜ๅˆฅ็ขผ๏ผˆ SerialNumber ๅฑฌๆ€ง๏ผ‰

caution

ๆ นๆ“šๆ“ไฝœ็ณป็ตฑ็‰ˆๆœฌๅ’ŒๆฌŠ้™๏ผŒๆœ‰ๆ™‚ๅฏ่ƒฝ็„กๆณ•็ฒๅ–ๆ“ไฝœ็ณป็ตฑ็š„็”ขๅ“่ญ˜ๅˆฅ็ขผ

้€™ๅ€‹่จŠๆฏๆœ‰ๆ™‚ๆœƒๅ—ๅˆฐไฟ่ญท๏ผŒๅชๆœ‰็ณป็ตฑ็ฎก็†ๅ“กๆฌŠ้™ๆ‰่ƒฝ่จชๅ•

using System;
using System.Management;

class Program
{
static void Main()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
ManagementObjectCollection collection = searcher.Get();

foreach (ManagementObject m in collection)
{
// ็ฒๅ–็”ขๅ“่ญ˜ๅˆฅ็ขผ
string productId = m["SerialNumber"].ToString();
Console.WriteLine("ๆ“ไฝœ็ณป็ตฑ็”ขๅ“่ญ˜ๅˆฅ็ขผ: " + productId);
}
}
catch (Exception e)
{
Console.WriteLine("็„กๆณ•็ฒๅ–ๆ“ไฝœ็ณป็ตฑ็”ขๅ“่ญ˜ๅˆฅ็ขผ: " + e.Message);
}
}
}