begin process at 2012 02 13 12:26:59
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive Visual Basic & VB.NET

 > 

Archives Visual Basic

 > 

J'AI BESOIN D'AIDE !!!! :)

 > 

Comment modifier le(s) propriétaire(s) d'un fichier ?


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Comment modifier le(s) propriétaire(s) d'un fichier ?

mercredi 18 juin 2003 à 16:08:10 | Comment modifier le(s) propriétaire(s) d'un fichier ?

Poch

Je n'ai pas de problèmes pour modifier les droits sur un fichiers, par contre je n'arrive pas à accéder au propriétaire (ou appartenance ).

Merci de votre aide.
vendredi 20 juin 2003 à 14:36:39 | Re : Comment modifier le(s) propriétaire(s) d'un fichier ?

Poch

J'ai trouvé la réponse à ma question dans la kb de msdn



Option Explicit

' Global constants we must use with security descriptor
Private Const SECURITY_DESCRIPTOR_REVISION = 1
Private Const OWNER_SECURITY_INFORMATION = 1&

' Access Token constants
Private Const TOKEN_ASSIGN_PRIMARY = &H1
Private Const TOKEN_DUPLICATE = &H2
Private Const TOKEN_IMPERSONATE = &H4
Private Const TOKEN_QUERY = &H8
Private Const TOKEN_QUERY_SOURCE = &H10
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_ADJUST_GROUPS = &H40
Private Const TOKEN_ADJUST_DEFAULT = &H80
Private Const TOKEN_ALL_ACCESS = TOKEN_ASSIGN_PRIMARY _
+ TOKEN_DUPLICATE + TOKEN_IMPERSONATE + TOKEN_QUERY _
+ TOKEN_QUERY_SOURCE + TOKEN_ADJUST_PRIVILEGES _
+ TOKEN_ADJUST_GROUPS + TOKEN_ADJUST_DEFAULT
Private Const ANYSIZE_ARRAY = 1

' Token Privileges constants
Private Const SE_RESTORE_NAME = "SeRestorePrivilege"
Private Const SE_PRIVILEGE_ENABLED = 2&

' ACL structure
Private Type ACL
AclRevision As Byte
Sbz1 As Byte
AclSize As Integer
AceCount As Integer
Sbz2 As Integer
End Type

Private Type SECURITY_DESCRIPTOR
Revision As Byte
Sbz1 As Byte
Control As Long
Owner As Long
Group As Long
Sacl As ACL
Dacl As ACL
End Type

' Token structures
Private Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type

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(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type

' Win32 API calls
Private Declare Function LookupAccountName Lib "advapi32.dll" _
Alias "LookupAccountNameA" (ByVal lpSystemName As String, _
ByVal lpAccountName As String, Sid As Byte, cbSid As Long, _
ByVal ReferencedDomainName As String, _
cbReferencedDomainName As Long, peUse As Integer) As Long

Private Declare Function InitializeSecurityDescriptor _
Lib "advapi32.dll" (pSecurityDescriptor As SECURITY_DESCRIPTOR, _
ByVal dwRevision As Long) As Long

Private Declare Function SetSecurityDescriptorOwner _
Lib "advapi32.dll" (pSecurityDescriptor As SECURITY_DESCRIPTOR, _
pOwner As Any, ByVal bOwnerDefaulted As Long) As Long

Private Declare Function SetFileSecurity Lib "advapi32.dll" _
Alias "SetFileSecurityA" (ByVal lpFileName As String, _
ByVal SecurityInformation As Long, _
pSecurityDescriptor As SECURITY_DESCRIPTOR) As Long

Private Declare Function OpenProcessToken Lib "advapi32.dll" _
(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" _
Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, _
ByVal lpName As String, lpLuid As LUID) As Long

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 CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Public Sub ChangeOwnerOfFile(FileName As String, _
OwnerAccountName As String)

' variables for the LookupAccountName API Call
Dim Sid(255) As Byte ' Buffer for the SID
Dim nBufferSize As Long ' Length of SID Buffer
Dim szDomainName As String * 255 ' Domain Name Buffer
Dim nDomain As Long ' Length of Domain Name buffer
Dim peUse As Integer ' SID type
Dim Result As Long ' Return value of Win32 API call

' variables for the InitializeSecurityDescriptor API Call
Dim SecDesc As SECURITY_DESCRIPTOR
Dim Revision As Long

Enable_Privilege (SE_RESTORE_NAME)

nBufferSize = 255
nDomain = 255

Result = LookupAccountName(vbNullString, OwnerAccountName, _
Sid(0), nBufferSize, szDomainName, nDomain, peUse)
If (Result = 0) Then
MsgBox "LookupAccountName failed with error code " _
& Err.LastDllError
Exit Sub
End If

Result = InitializeSecurityDescriptor(SecDesc, _
SECURITY_DESCRIPTOR_REVISION)
If (Result = 0) Then
MsgBox "InitializeSecurityDescriptor failed with error code " _
& Err.LastDllError
Exit Sub
End If

Result = SetSecurityDescriptorOwner(SecDesc, Sid(0), 0)
If (Result = 0) Then
MsgBox "SetSecurityDescriptorOwner failed with error code " _
& Err.LastDllError
Exit Sub
End If

Result = SetFileSecurity(FileName, OWNER_SECURITY_INFORMATION, _
SecDesc)
If (Result = 0) Then
MsgBox "SetFileSecurity failed with error code " _
& Err.LastDllError
Exit Sub
Else
MsgBox "Owner of " & FileName & " changed to " _
& OwnerAccountName
End If

Disable_Privilege (SE_RESTORE_NAME)

End Sub

Public Function Enable_Privilege(Privilege As String) As Boolean
Enable_Privilege = ModifyState(Privilege, True)
End Function

Public Function Disable_Privilege(Privilege As String) As Boolean
Disable_Privilege = ModifyState(Privilege, False)
End Function

Public Function ModifyState(Privilege As String, _
Enable As Boolean) As Boolean

Dim MyPrives As TOKEN_PRIVILEGES
Dim PrivilegeId As LUID
Dim ptrPriv As Long ' Pointer to Privileges Structure
Dim hToken As Long ' Token Handle
Dim Result As Long ' Return Value

Result = OpenProcessToken(GetCurrentProcess(), _
TOKEN_ADJUST_PRIVILEGES, hToken)
If (Result = 0) Then
ModifyState = False
MsgBox "OpenProcessToken failed with error code " _
& Err.LastDllError
Exit Function
End If

Result = LookupPrivilegeValue(vbNullString, Privilege, PrivilegeId)
If (Result = 0) Then
ModifyState = False
MsgBox "LookupPrivilegeValue failed with error code " _
& Err.LastDllError
Exit Function
End If

MyPrives.Privileges(0).pLuid = PrivilegeId
MyPrives.PrivilegeCount = 1
If (Enable) Then
MyPrives.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
Else
MyPrives.Privileges(0).Attributes = 0
End If

Result = AdjustTokenPrivileges(hToken, False, MyPrives, 0, 0, 0)
If (Result = 0 Or Err.LastDllError <> 0) Then
ModifyState = False
MsgBox "AdjustTokenPrivileges failed with error code " _
& Err.LastDllError
Exit Function
End If

CloseHandle hToken

ModifyState = True

End Function





-------------------------------
Réponse au message :
-------------------------------

> Je n'ai pas de problèmes pour modifier les droits sur un fichiers, par contre je n'arrive pas à accéder au propriétaire (ou appartenance ).
>
> Merci de votre aide.
vendredi 21 juillet 2006 à 09:44:44 | Re : Comment modifier le(s) propriétaire(s) d'un fichier ?

flyingfish

Salut

Et le même en VB Script ?

C'est possible ? 

Merci d'avance

    /\_    /\ 
  /      \/    \



Cette discussion est classée dans : fichier, modifier, propriétaire


Répondre à ce message

Sujets en rapport avec ce message

Modificatin du propriétaire d'un fichier [ par flyingfish ] Bonjour,Il y a quelques années, une réponse a été donnée pour modifier le propriétaire d'un document. Cela fonctionne très bien avec VBhttp://www.vbfr Allèger la taille d'un fichier [ par mistygirl ] Bonsoir, j'ai un problème avec l'application excel que je suis en train de créer : le fichier prend de plus en plus de place (36Mo actuellement) et ça MODIFIER DATE ET HEURE D'UN FICHIER [ par ccclooo ] Désolé, mais j'ai téchargé le logiciel "MODIFIER DATE ET HEURE D'UN FICHIER" en cliquant sur le lien "téléchargé le Zip", et an décompressant ce zip i modifier ligne fichier text [ par jerome57440 ] bonjour, je suis débutant en vb et j'ai une petite question.Serait-il possible de rajouter tu texte a la suite d'une ligne dans un fichier text.Mes Modifier des données d'un fichier csv [ par neo6583 ] Je travaille sur un fichier csv, et je suis amené à en faire une mise a jours automatique. Je cherche tout simplement le moyen de modifier une valeur Modifier les propriétés d'un fichier [ par JACKY007 ] Bonjour,Je suis à la recherche d'un code me permettant de modifier dans les propriétés d'un document (non office), et en particulier son objet et son Modifier fichier .ini [ par informatixa ] Bonjour,Voila mon fichier .iniresolution 1024 768fullscreen 1texture 1view 2detail 2distant 1shadow 1bloom 0Je voudrais modifier le "2" de la ligne "v Modifier date du dernier accès à un fichier [ par lilinath ] Bonjour, Je désire changer la date du dernier accès à un fichier, vidéo. Je n'y arrive pas. Quelqu'un peut il m'aider. Merci pour votre aide,Bonne j Ouvrir un fichier bin lisible pour le modifier ? [ par kedji ] Bonjour , étant débutant mais ayant la soif de conaissance , je vien vous posez une question , bref . Voila j' ai ce fichier qui vient d' un jeu , et


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 3,463 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales