Re: Getting Windows "MACHINE SID" without fork() & exec()?

Corinna Vinschen via Cygwin <[email protected]> Fri, 24 Apr 2026 14:11:00 +0200
Newsgroups gmane.os.cygwin
Message-ID <[email protected]>
On Apr 23 19:07, Takeshi Nishimura via Cygwin wrote:
> Does Cygwin have a secret shell variable or /proc file which contains
> the current machine's MACHINE SID, without having to resort to calling
> an external program (no fork(), no exec(), please)?

You can use your own simple tool in plain C:

$ cat > adom.c <<EOF
#include <stdio.h>
#include <windows.h>
#include <ntsecapi.h>
#include <ntstatus.h>
#include <sddl.h>

int
main ()
{
  LSA_OBJECT_ATTRIBUTES oa = { 0, 0, 0, 0, 0, 0 };
  PPOLICY_ACCOUNT_DOMAIN_INFO adom;
  NTSTATUS status;
  LPWSTR sidstr;
  HANDLE lsa;

  status = LsaOpenPolicy(NULL, &oa, POLICY_VIEW_LOCAL_INFORMATION, &lsa);
  if (status == STATUS_SUCCESS)
    {
      status = LsaQueryInformationPolicy (lsa, PolicyAccountDomainInformation,
                                          (PVOID *) &adom);
      if (status == STATUS_SUCCESS)
        {
          ConvertSidToStringSidW (adom->DomainSid, &sidstr);
          printf ("%ls\n", sidstr);
          LocalFree (sidstr);
        }
      LsaFreeMemory (adom);
      LsaClose (lsa);
    }
  return 0;
}
EOF
$ gcc -o adom adom.c
$ ./adom
S-1-5-21-2941109648-2854651930-1480659642


Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple