none
Computer's SID

    Question

  • Hi, pardon me if I am wrong in this Forum, but I have a Windows related question I have to get out :)

    I need to Check for the Computer's SID in order to compare between some Terminal Servers. They may have been built by Image, so if the SID is all the same through the Farm, it would be unpleasant. I found the User SID right away in registry HKEY_USERS\SID but not the Computer's SID..

    thanks for Help

    Tobias
    Thursday, October 05, 2006 11:07 AM

All replies

  • Sysinternals has a tool for reading SIDs:

    http://www.sysinternals.com/Utilities/PsGetSid.html

     

    Thursday, October 05, 2006 9:02 PM
  • I've actually found some WMI code for getting the computer SID although not working as expected to...just thought I would let you know that there is some code
    Thursday, October 05, 2006 9:31 PM
  • plvoy, with the Microsoft .NET Framework 2.0 or later, you can use the following C# code to get the SID of the Computer.

    using System;
    using System.Security.Principal;

    static void Main(string[] args)
    {
    WindowsIdentity wi = WindowsIdentity.GetCurrent();
    Console.WriteLine("The Computer's SID is:\n\n{0}\n\n", wi.User.AccountDomainSid);

    }

    Monday, July 14, 2008 12:58 AM
  • plvoy, with the Microsoft .NET Framework 2.0 or later, you can use the following C# code to get the SID of the Computer.

    using System;
    using System.Security.Principal;

    static void Main(string[] args)
    {
    WindowsIdentity wi = WindowsIdentity.GetCurrent();
    Console.WriteLine("The Computer's SID is:\n\n{0}\n\n", wi.User.AccountDomainSid);

    }


    I'm not sure it returns the computer SID when you're in a domain and using a domain user account.
    Tuesday, March 31, 2009 9:52 PM
  • I've combined a number of things that I've seen in various posts and come up with this line of code to get the Computer Sid from C#. For brevity I'm using .NET 3.5 and LINQ but this could easily be reconstructed to not use LINQ and work in .NET 2.0. I've tested it on domain and non-domain computers and it returns the same SID as sysinternals psGetSid. Enjoy.

    using System;
    using System.Security.Principal;
    using System.DirectoryServices;
    using System.Linq;

    public static SecurityIdentifier GetComputerSid()
    {
    return new SecurityIdentifier((byte[])new DirectoryEntry(string.Format("WinNT://{0},Computer", Environment.MachineName)).Children.Cast<DirectoryEntry>().First().InvokeGet("objectSID"), 0).AccountDomainSid;
    }
    Tuesday, January 19, 2010 8:27 PM
  • This Worked for me by converting to vb.
    First thing to remember is to use the "DirectoryEntry" first add a reference to the  System.DirectoryServices then also in vb add a imports.  Using this code i was also able to get the same Sid As the psgGetSid     (What is wrong with the editor here Had to edit the html by hand to get the font biger again)
    Imports System
    Imports System.Management
    Imports System.Security.Principal
    Imports System.DirectoryServices
    
       Public Shared Function GetComputerSid() As SecurityIdentifier
    
    
    
            Return New SecurityIdentifier(DirectCast(New DirectoryEntry(String.Format("WinNT://{0},Computer", Environment.MachineName)) _
                                          .Children.Cast(Of DirectoryEntry)().First().InvokeGet("objectSID"), Byte()), 0).AccountDomainSid
    
        End Function
    
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim nsid As String
            nsid = GetComputerSid().ToString
            TextBox2.Text = nsid
    
    
        End Sub
    Thursday, October 20, 2011 5:19 AM