How to read the Computer SID?
-
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
-
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
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:
-
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:
Hello, on my computer Vista, no domain, the hive \\hklm\security is complete empty :-( \\hklm\sam\sam is empty too Stefan
-
Hello, on my computer Vista, no domain, the hive \\hklm\security is complete empty :-( \\hklm\sam\sam is empty too Stefan
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
-
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
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