I have a Windows service that needs to access registry hives under HKEY_USERS when users log on, either locally or via Terminal Server. I\'m using a WMI query on win32_logon
Powershell is easier.
Function GetSIDfromAcctName() { $myacct = Get-WmiObject Win32_UserAccount -filter "Name = '$env:USERNAME " write-host Name: $myacct.name Write-Host SID : $myacct.sid }