Accueil > > > SAVOIR SI UN USAGER A ACCESS À UN FICHIER OU UN DOSSIER
SAVOIR SI UN USAGER A ACCESS À UN FICHIER OU UN DOSSIER
Information sur la source
Description
reçoi un nom de fichier et un mask et permet de savoir si on a acces à ce dossier j'ai pris une partie du code ici, masi j'ai du modifier beaucoup pour avoir se résultat. par contre, ça risque d,en aider plusieurs exemple : If GetAccess(fichier, GENERIC_EXECUTE Or GENERIC_READ) Then
Source
- Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
- Declare Function LookupAccountName Lib "advapi32.dll" Alias "LookupAccountNameA" (lpSystemName As String, ByVal lpAccountName As String, sid As Any, cbSid As Long, ByVal ReferencedDomainName As String, cbReferencedDomainName As Long, peUse As Long) As Long
- Declare Function GetFileSecurity Lib "advapi32.dll" Alias "GetFileSecurityA" (ByVal lpFileName As String, ByVal RequestedInformation As Long, pSecurityDescriptor As Byte, ByVal nLength As Long, lpnLengthNeeded As Long) As Long
- Declare Function GetFileSecurityN Lib "advapi32.dll" Alias "GetFileSecurityA" (ByVal lpFileName As String, ByVal RequestedInformation As Long, ByVal pSecurityDescriptor As Long, ByVal nLength As Long, lpnLengthNeeded As Long) As Long
-
-
- ' The file/security API call constants.
- ' Refer to the MSDN for more information on how/what these constants
- ' are used for.
- Public Const DACL_SECURITY_INFORMATION = &H4
-
- Public Const GENERIC_READ = &H80000000
- Public Const GENERIC_EXECUTE = &H20000000
-
- 'savoir si on a acces au fichier ou dossier
- Public Function GetAccess(ByVal sFileName As String, lMask As Long) As Boolean
-
- Dim strUserName As String
- Dim lResult As Long ' Result of various API calls.
-
- Dim bUserSid(255) As Byte ' This will contain your SID.
-
- Dim lUserSID As Long ' Used to hold the SID of the
- ' current user.
- Dim lSIDType As Long ' The type of SID info we are
- ' getting back.
- Dim lFileSDSize As Long ' Size of the File SD.
- Dim lSizeNeeded As Long ' Size needed for SD for file.
-
-
- Dim sDomainName As String * 255 ' Domain the user belongs to.
- Dim lDomainNameLength As Long ' Length of domain name needed.
-
- Dim bSDBuf() As Byte ' Buffer that holds the security
- ' descriptor for this file.
-
- GetAccess = False
-
- Dim temp As Integer
-
- If InStr(Mid(sFileName, 2), "*") <> 0 Then
- sFileName = Mid(sFileName, InStr(Mid(sFileName, 2), "*") + 2)
- End If
- 'Create a buffer
- strUserName = String(100, Chr$(0))
- 'Get the username
- GetUserName strUserName, 100
- 'strip the rest of the buffer
- strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
- ' Get the SID of the user. (Refer to the MSDN for more information on SIDs
- ' and their function/purpose in the operating system.) Get the SID of this
- ' user by using the LookupAccountName API. In order to use the SID
- ' of the current user account, call the LookupAccountName API
- ' twice. The first time is to get the required sizes of the SID
- ' and the DomainName string. The second call is to actually get
- ' the desired information.
-
- lResult = LookupAccountName(vbNullString, strUserName, _
- bUserSid(0), 255, sDomainName, lDomainNameLength, _
- lSIDType)
-
- ' Now set the sDomainName string buffer to its proper size before
- ' calling the API again.
- sDomainName = Space(lDomainNameLength)
-
- ' Call the LookupAccountName again to get the actual SID for user.
- lResult = LookupAccountName(vbNullString, strUserName, _
- bUserSid(0), 255, sDomainName, lDomainNameLength, _
- lSIDType)
-
- ' Return value of zero means the call to LookupAccountName failed;
- ' test for this before you continue.
- If (lResult = 0) Then
- MsgBox "Error: Unable to Lookup the Current User Account: " _
- & sUserName
- Exit Function
- End If
-
- ' You now have the SID for the user who is logged on.
- ' The SID is of interest since it will get the security descriptor
- ' for the file that the user is interested in.
- ' The GetFileSecurity API will retrieve the Security Descriptor
- ' for the file. However, you must call this API twice: once to get
- ' the proper size for the Security Descriptor and once to get the
- ' actual Security Descriptor information.
-
- lResult = GetFileSecurityN(sFileName, DACL_SECURITY_INFORMATION, _
- 0, 0, lSizeNeeded)
-
- ' Redimension the Security Descriptor buffer to the proper size.
- ReDim bSDBuf(lSizeNeeded)
-
- ' Now get the actual Security Descriptor for the file.
- lResult = GetFileSecurity(sFileName, DACL_SECURITY_INFORMATION, _
- bSDBuf(0), lSizeNeeded, lSizeNeeded)
-
- ' A return code of zero means the call failed; test for this
- ' before continuing.
- If (lResult <> 0) Then
- GetAccess = True
- End If
- End Function
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function LookupAccountName Lib "advapi32.dll" Alias "LookupAccountNameA" (lpSystemName As String, ByVal lpAccountName As String, sid As Any, cbSid As Long, ByVal ReferencedDomainName As String, cbReferencedDomainName As Long, peUse As Long) As Long
Declare Function GetFileSecurity Lib "advapi32.dll" Alias "GetFileSecurityA" (ByVal lpFileName As String, ByVal RequestedInformation As Long, pSecurityDescriptor As Byte, ByVal nLength As Long, lpnLengthNeeded As Long) As Long
Declare Function GetFileSecurityN Lib "advapi32.dll" Alias "GetFileSecurityA" (ByVal lpFileName As String, ByVal RequestedInformation As Long, ByVal pSecurityDescriptor As Long, ByVal nLength As Long, lpnLengthNeeded As Long) As Long
' The file/security API call constants.
' Refer to the MSDN for more information on how/what these constants
' are used for.
Public Const DACL_SECURITY_INFORMATION = &H4
Public Const GENERIC_READ = &H80000000
Public Const GENERIC_EXECUTE = &H20000000
'savoir si on a acces au fichier ou dossier
Public Function GetAccess(ByVal sFileName As String, lMask As Long) As Boolean
Dim strUserName As String
Dim lResult As Long ' Result of various API calls.
Dim bUserSid(255) As Byte ' This will contain your SID.
Dim lUserSID As Long ' Used to hold the SID of the
' current user.
Dim lSIDType As Long ' The type of SID info we are
' getting back.
Dim lFileSDSize As Long ' Size of the File SD.
Dim lSizeNeeded As Long ' Size needed for SD for file.
Dim sDomainName As String * 255 ' Domain the user belongs to.
Dim lDomainNameLength As Long ' Length of domain name needed.
Dim bSDBuf() As Byte ' Buffer that holds the security
' descriptor for this file.
GetAccess = False
Dim temp As Integer
If InStr(Mid(sFileName, 2), "*") <> 0 Then
sFileName = Mid(sFileName, InStr(Mid(sFileName, 2), "*") + 2)
End If
'Create a buffer
strUserName = String(100, Chr$(0))
'Get the username
GetUserName strUserName, 100
'strip the rest of the buffer
strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
' Get the SID of the user. (Refer to the MSDN for more information on SIDs
' and their function/purpose in the operating system.) Get the SID of this
' user by using the LookupAccountName API. In order to use the SID
' of the current user account, call the LookupAccountName API
' twice. The first time is to get the required sizes of the SID
' and the DomainName string. The second call is to actually get
' the desired information.
lResult = LookupAccountName(vbNullString, strUserName, _
bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)
' Now set the sDomainName string buffer to its proper size before
' calling the API again.
sDomainName = Space(lDomainNameLength)
' Call the LookupAccountName again to get the actual SID for user.
lResult = LookupAccountName(vbNullString, strUserName, _
bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)
' Return value of zero means the call to LookupAccountName failed;
' test for this before you continue.
If (lResult = 0) Then
MsgBox "Error: Unable to Lookup the Current User Account: " _
& sUserName
Exit Function
End If
' You now have the SID for the user who is logged on.
' The SID is of interest since it will get the security descriptor
' for the file that the user is interested in.
' The GetFileSecurity API will retrieve the Security Descriptor
' for the file. However, you must call this API twice: once to get
' the proper size for the Security Descriptor and once to get the
' actual Security Descriptor information.
lResult = GetFileSecurityN(sFileName, DACL_SECURITY_INFORMATION, _
0, 0, lSizeNeeded)
' Redimension the Security Descriptor buffer to the proper size.
ReDim bSDBuf(lSizeNeeded)
' Now get the actual Security Descriptor for the file.
lResult = GetFileSecurity(sFileName, DACL_SECURITY_INFORMATION, _
bSDBuf(0), lSizeNeeded, lSizeNeeded)
' A return code of zero means the call failed; test for this
' before continuing.
If (lResult <> 0) Then
GetAccess = True
End If
End Function
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|