http://www.perlmonks.org?node_id=617564

anadem has asked for the wisdom of the Perl Monks concerning the following question:

I humbly request enlightenment on the issue of obtaining the current UserSID in perl on Windows. Searches in the googolsphere have been entertaining but ultimately fruitless -- can any kind monks give me help?

(The need is to access the registry from a process running under msiexec --an install-- when the "current user" is not the logged-in user because the process is running with system privilege. By reading from HKU\UserSID I can reach the right data.

The Windows API function LookupAccountName returns a SID structure, but somehow I can't find the CPAN digest which reportedly implements that.)

Replies are listed 'Best First'.
Re: getting UserSID in Windows
by Albannach (Monsignor) on May 25, 2007 at 19:25 UTC
    Whenever I have a problem with Win32 permissions and Perl I think of Dave Roth's Win32::Perms and sure enough there is even an article with an example that should help you out.

    --
    I'd like to be able to assign to an luser

      Thank you for an excellent reference!
Re: getting UserSID in Windows
by ikegami (Patriarch) on May 29, 2007 at 20:07 UTC

    The Windows API function LookupAccountName returns a SID structure, but somehow I can't find the CPAN digest which reportedly implements that.)

    Arbitrary Windows API functions can be called using Win32::API.

Re: getting UserSID in Windows
by girarde (Hermit) on May 29, 2007 at 16:07 UTC
    Something like
    use Win32::OLE; use Win32::OLE::Const ('Active DS'); my $user = Win32::OLE->GetObject("LDAP://$distinguishedName"); my $SID = $user->{objectSID};
    or words to that effect should do it.