Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to read the Computer SID?

How to read the Computer SID?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++tutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StefanKittel
    wrote on last edited by
    #1

    Hello, to identify local machines I need to read the Computer SID. (like psgetsid.exe does) Does anybody have a bit of source for this? OS: Windows 2000 and up. Compiler: VC9 using MFC (not C#). But I'll take anything you have even VB or Delphy Mention: Computer SID, not a logon, user SID. Any computer have one. It don't need to be in a domain. I searched hours in google and forums. Thanks in advance Stefan

    M 1 Reply Last reply
    0
    • S StefanKittel

      Hello, to identify local machines I need to read the Computer SID. (like psgetsid.exe does) Does anybody have a bit of source for this? OS: Windows 2000 and up. Compiler: VC9 using MFC (not C#). But I'll take anything you have even VB or Delphy Mention: Computer SID, not a logon, user SID. Any computer have one. It don't need to be in a domain. I searched hours in google and forums. Thanks in advance Stefan

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      From what I can find, the last 96 bits of HKEY_LOCAL_MACHINE\SECURITY\SAM\Domains\Account\V is the machine SID. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        From what I can find, the last 96 bits of HKEY_LOCAL_MACHINE\SECURITY\SAM\Domains\Account\V is the machine SID. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        S Offline
        S Offline
        StefanKittel
        wrote on last edited by
        #3

        Hello, on my computer Vista, no domain, the hive \\hklm\security is complete empty :-( \\hklm\sam\sam is empty too Stefan

        M 1 Reply Last reply
        0
        • S StefanKittel

          Hello, on my computer Vista, no domain, the hive \\hklm\security is complete empty :-( \\hklm\sam\sam is empty too Stefan

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          You have to enable viewing - by default (even if you're an administrator), you don't have read rights in the security key. You can give yourself permissions in regedit however. Anyway, I played around with this, and the following code gives me the same SID found in that registry hive (on Vista):

          DWORD SIDLength = 0;
          DWORD RefDomainNameLength = 0;
          SID\_NAME\_USE SIDNameUse;
          ::LookupAccountName(NULL, \_T("MYCOMPUTERNAME\\\\"), NULL, &SIDLength, NULL, &RefDomainNameLength, &SIDNameUse);
          PSID psid = (PSID)new BYTE\[SIDLength\];
          LPTSTR domain = new TCHAR\[RefDomainNameLength\];
          ::LookupAccountName(NULL, \_T("MYCOMPUTERNAME\\\\"), psid, &SIDLength, domain, &RefDomainNameLength, &SIDNameUse);
          
          //... use the SID (psid) here ...
          
          // \*\* Test \*\*
          LPTSTR StringSid;
          ::ConvertSidToStringSid(psid, &StringSid);
          ::LocalFree(StringSid);
          // \*\* End Test \*\*
          
          delete\[\] domain;
          delete\[\] (BYTE\*)psid;
          

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          modified on Saturday, August 30, 2008 11:45

          S 1 Reply Last reply
          0
          • M Mark Salsbery

            You have to enable viewing - by default (even if you're an administrator), you don't have read rights in the security key. You can give yourself permissions in regedit however. Anyway, I played around with this, and the following code gives me the same SID found in that registry hive (on Vista):

            DWORD SIDLength = 0;
            DWORD RefDomainNameLength = 0;
            SID\_NAME\_USE SIDNameUse;
            ::LookupAccountName(NULL, \_T("MYCOMPUTERNAME\\\\"), NULL, &SIDLength, NULL, &RefDomainNameLength, &SIDNameUse);
            PSID psid = (PSID)new BYTE\[SIDLength\];
            LPTSTR domain = new TCHAR\[RefDomainNameLength\];
            ::LookupAccountName(NULL, \_T("MYCOMPUTERNAME\\\\"), psid, &SIDLength, domain, &RefDomainNameLength, &SIDNameUse);
            
            //... use the SID (psid) here ...
            
            // \*\* Test \*\*
            LPTSTR StringSid;
            ::ConvertSidToStringSid(psid, &StringSid);
            ::LocalFree(StringSid);
            // \*\* End Test \*\*
            
            delete\[\] domain;
            delete\[\] (BYTE\*)psid;
            

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            modified on Saturday, August 30, 2008 11:45

            S Offline
            S Offline
            StefanKittel
            wrote on last edited by
            #5

            Hello, that looks great. I ignored LookupAccountName because, reading in the msdn, it should be only working with a PDC. I try this out. Thanks Stefan

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups