using System;
using System.Linq;
using System.Management;
using System.Security.Principal;
namespace ConsoleTest
{
class Program
{
static void Main(string[] args)
{
new Program().Run(args);
}
private void Run(string[] args)
{
string sid = UserSecurityId();
Console.WriteLine("The SID is: {0}", sid);
string[] processorIds = ComputerProcessorId();
foreach (string id in processorIds)
{
Console.WriteLine("Processor ID: {0}", id);
}
}
public string UserSecurityId()
{
return WindowsIdentity.GetCurrent().User.AccountDomainSid.ToString();
}
public string[] ComputerProcessorId()
{
return new ManagementObjectSearcher("Select * from Win32_Processor")
.Get()
.OfType<ManagementObject>()
.Select(o => o["ProcessorID"].ToString())
.ToArray();
}
}
}
Just some random development ramblings mostly related to the Microsoft .NET platform.
Saturday, January 31, 2009
Obtaining computer SID and Processor ID using C#
Sometimes you have to track a unique identifier for an application (e.g. license key registration). Here are two small C# methods to get the Windows SID (Security ID) and the motherboard processor ID (may be more than one).
Subscribe to:
Post Comments (Atom)
Can't RDP? How to enable / disable virtual machine firewall for Azure VM
Oh no! I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore. I did ...
-
Here is a full test program that demonstrates how to use SharpZipLib to zip an XElement into a byte array. This allows you to transfer larg...
-
Oh no! I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore. I did ...
No comments:
Post a Comment