1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
'Les déclarations
Dim RetVal As Long
Private Type LUID
LowPart As Long
HighPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(1) As LUID_AND_ATTRIBUTES
End Type
Private TP As TOKEN_PRIVILEGES
Private Const TOKEN_ADJUST_PRIVLEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const HKEY_USERS = &H80000003
Private Const SE_RESTORE_NAME = "SeRestorePrivilege"
Private Const SE_BACKUP_NAME = "SeBackupPrivilege"
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" _
(ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, _
NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, _
ByVal PreviousState As Long, ByVal ReturnLength As Long) As Long
Private Declare Function RegLoadKey Lib "advapi32.dll" Alias "RegLoadKeyA" _
(ByVal Hkey As Long, ByVal lpSubKey As String, ByVal lpFile As String) _
As Long
RetVal = OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVLEGES Or TOKEN_QUERY, MyToken)
RetVal = LookupPrivilegeValue(vbNullString, SE_RESTORE_NAME, RestoreLuid)
RetVal = LookupPrivilegeValue(vbNullString, SE_BACKUP_NAME, BackupLuid)
'La fonction
Public Function ChargeRuche(ByRef RetCode As Long, ByVal Ruche As String, ByVal Chemin As String)
'initialisation de la structure
TP.Initialize()
'affectation des éléments de la structure
TP.PrivilegeCount = 2
TP.Privileges(0).pLuid = RestoreLuid
TP.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
TP.Privileges(1).pLuid = BackupLuid
TP.Privileges(1).Attributes = SE_PRIVILEGE_ENABLED
RetVal = AdjustTokenPrivileges(MyToken, TriState.False, TP, Len(TP), 0, 0)
RetVal = RegLoadKey(HKEY_USERS, Ruche, Chemin)
RetCode = RetVal
RetVal = AdjustTokenPrivileges(MyToken, TriState.True, TP, Len(TP), 0, 0)
End Function |
Partager