Как определить SID пользователя по его имени?
И как потом писать в его ветку реестра HKEY_USERS?
Как я понимаю, она будет доступна только с правами SYSTEM?
Option Explicit
Private Declare Function GetUserName Lib "advapi32" Alias "GetUserNameA" (ByVal lpBuffer As String, ByRef nSize As Long) As Long
Private Declare Function LookupAccountName Lib "advapi32" Alias "LookupAccountNameA" (ByVal lpSystemName As String, ByVal lpAccountName As String, SID As Any, ByRef cbSid As Long, ByVal ReferencedDomainName As String, ByRef cbReferencedDomainName As Long, ByRef peUse As Integer) As Long
Private Declare Function ConvertSidToStringSid Lib "advapi32" Alias "ConvertSidToStringSidA" (SID As Any, pStringSID As Long) As Long
Private Declare Function SysAllocString Lib "oleaut32" (ByVal pOlechar As Long) As String
Private Declare Function LocalFree Lib "kernel32" (ByVal hMem As Long) As Long
Sub Main()
Dim UserName As String * 256, Length As Long: Length = 256
GetUserName UserName, Length
Debug.Print UserName
Dim SID As String * 256 ':-P
LookupAccountName vbNullString, UserName, ByVal SID, 256, Space(256), 256, 0
Dim pStringSID As Long
ConvertSidToStringSid ByVal SID, pStringSID
Debug.Print SysAllocString(pStringSID)
LocalFree pStringSID
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 129