三九宝宝网宝宝百科宝宝知识

VB取得磁盘文件夹或文件的security

11月21日 编辑 39baobao.com

[如何打印CAD文件]2CTRL+P,弹出打印对话框。依次选择打印机名称、图纸尺寸、打印范围选择窗口、打印比例选择布满图纸。3当把打印范围选为窗口后,选择你要打印的范围【拉动鼠标选出一个矩形框...+阅读

实现代码如下:

Option Explicit

Public Const MAXIMUM_ALLOWED As Long = &H2000000

Public Const DELETE As Long = &H10000

Public Const READ_CONTROL As Long = &H20000

Public Const WRITE_DAC As Long = &H40000

Public Const WRITE_OWNER As Long = &H80000

Public Const SYNCHRONIZE As Long = &H100000

Public Const STANDARD_RIGHTS_READ As Long = READ_CONTROL

Public Const STANDARD_RIGHTS_WRITE As Long = READ_CONTROL

Public Const STANDARD_RIGHTS_EXECUTE As Long = READ_CONTROL

Public Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000

Public Const FILE_READ_DATA As Long = &H1

Public Const FILE_LIST_DIRECTORY As Long = &H1

Public Const FILE_ADD_FILE As Long = &H2

Public Const FILE_WRITE_DATA As Long = &H2

Public Const FILE_CREATE_PIPE_INSTANCE As Long = &H4

Public Const FILE_ADD_SUBDIRECTORY As Long = &H4

Public Const FILE_APPEND_DATA As Long = &H4

Public Const FILE_READ_EA As Long = &H8

Public Const FILE_READ_PROPERTIES As Long = FILE_READ_EA

Public Const FILE_WRITE_EA As Long = &H10

Public Const FILE_WRITE_PROPERTIES As Long = FILE_WRITE_EA

Public Const FILE_EXECUTE As Long = &H20

Public Const FILE_TRAVERSE As Long = &H20

Public Const FILE_DELETE_CHILD As Long = &H40

Public Const FILE_READ_ATTRIBUTES As Long = &H80

Public Const FILE_WRITE_ATTRIBUTES As Long = &H100

Public Const FILE_GENERIC_READ As Long = (STANDARD_RIGHTS_READ Or FILE_READ_DATA Or FILE_READ_ATTRIBUTES Or FILE_READ_EA Or FILE_EXECUTE Or STANDARD_RIGHTS_EXECUTE Or SYNCHRONIZE)

Public Const FILE_GENERIC_READ As Long = (STANDARD_RIGHTS_READ Or FILE_READ_DATA Or FILE_READ_ATTRIBUTES Or FILE_READ_EA Or SYNCHRONIZE)

Public Const FILE_GENERIC_EXECUTE As Long = (STANDARD_RIGHTS_EXECUTE Or FILE_READ_ATTRIBUTES Or FILE_EXECUTE Or SYNCHRONIZE)

Public Const FILE_GENERIC_WRITE As Long = (STANDARD_RIGHTS_WRITE Or FILE_WRITE_DATA Or FILE_WRITE_ATTRIBUTES Or FILE_WRITE_EA Or FILE_APPEND_DATA Or SYNCHRONIZE)

Public Const FILE_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &H1FF&)

Public Const GENERIC_READ As Long = &H80000000

Public Const GENERIC_WRITE As Long = &H40000000

Public Const GENERIC_EXECUTE As Long = &H20000000

Public Const GENERIC_ALL As Long = &H10000000

' Types, constants and functions to work with access rights

Public Const OWNER_SECURITY_INFORMATION As Long = &H1

Public Const GROUP_SECURITY_INFORMATION As Long = &H2

Public Const DACL_SECURITY_INFORMATION As Long = &H4

Public Const TOKEN_QUERY As Long = 8

Public Const SecurityImpersonation As Integer = 3

Public Const ANYSIZE_ARRAY = 1

Public Const ACEListDirectory = 1

Public Const ACEReadData = 1

Public Const ACECreateFiles = 2

Public Const ACEWriteData = 2

Public Const ACECreateDirectories = 4

Public Const ACEAppendData = 4

Public Const ACEReadExtendedAttributes = 8

Public Const ACEWriteExtendedAttributes = 16

Public Const ACEExecuteFile = 32

Public Const ACETrerse = 32

Public Const ACEDeleteSubdirectoriesAndFiles = 64

Public Const ACEReadAttributes = 128

Public Const ACEWriteAttributes = 256

'Public Const ACEWrite = 278

Public Const ACEDelete = 65536

Public Const ACEReadPermissions = 131072

'Public Const ACERead = 131209

'Public Const ACEReadAndExecute = 131241

'Public Const ACEModify = 197055

Public Const ACEChangePermissions = 262144

Public Const ACETakeOwnership = 524288

Public Const ACESynchronize = 1048576

'Public Const ACEFullControl = 2032127

Public Type GENERIC_MAPPING

GenericRead As Long

GenericWrite As Long

GenericExecute As Long

GenericAll As Long

End Type

Public Type LUID

LowPart As Long

HighPart As Long

End TypePublic Type LUID_AND_ATTRIBUTES

pLuid As LUID

Attributes As Long

End Type

Public Type PRIVILEGE_SET

PrivilegeCount As Long

Control As Long

Privilege(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES

End Type

Public Declare Function GetFileSecurity Lib "advapi32.dll" Alias "GetFileSecurityA" (ByVal lpFileName As String,ByVal RequestedInformation As Long, pSecurityDeor As Byte,ByVal nLength As Long, lpnLengthNeeded As Long) As Long

Public Declare Function AccessCheck Lib "advapi32.dll" (pSecurityDeor As Byte, ByVal ClientToken As Long,ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING,PrivilegeSet As PRIVILEGE_SET, PrivilegeSetLength As Long, GrantedAccess As Long, Status As Long) As Long

Public Declare Function ImpersonateSelf Lib "advapi32.dll" (ByVal ImpersonationLevel As Integer) As Long

Public Declare Function RevertToSelf Lib "advapi32.dll" () As Long

Public Declare Sub MapGenericMask Lib "advapi32.dll" (AccessMask As Long,GenericMapping As GENERIC_MAPPING)

Public Declare Function OpenThreadToken Lib "advapi32.dll"(ByVal ThreadHandle As Long, ByVal DesiredAccess As Long,ByVal OpenAsSelf As Long, TokenHandle As Long) As Long

Public Declare Function GetCurrentThread Lib "kernel32" () As Long

Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Type OSVERSIONINFO

dwOSVersionInfoSize As Long

dwMajorVersion As Long

dwMinorVersion As Long

dwBuildNumber As Long

dwPlatformId As Long

szCSDVersion As String * 128

End Type

Public Const VER_PLATFORM_WIN32_NT As Long = 2

Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _

(lpVersionInformation As OSVERSIONINFO) As Long

Public Const FS_PERSISTENT_ACLS As Long = &H8

Public Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String,ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long,lpVolumeSerialNumber As Long, lpMaximumponentLength As Long,lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String,ByVal nFileSystemNameSize As Long) As Long

’检查文件的访问权限

Public Function CheckFileAccess(fileName As String, ByVal DesiredAccess As Long) As Long

Dim r As Long, SecDesc() As Byte, SDSize As Long, hToken As Long

Dim PrivSet As PRIVILEGE_SET, GenMap As GENERIC_MAPPING

Dim Volume As String, FSFlags As Long

If Not IsNT() Then

CheckFileAccess = -1

Exit Function

End If

If Left$(fileName, 2) = "\\" Then

r = InStr(3, fileName, "\")

If r = 0 Then

Volume = fileName & "\"

Else

Volume = Left$(fileName, r)

End If

ElseIf Mid$(fileName, 2, 2) = ":\" Then

Volume = Left$(fileName, 3)

End If

GetVolumeInformation Volume, vbNullString, 0, ByVal 0&, _

ByVal 0&, FSFlags, vbNullString, 0

If (FSFlags And FS_PERSISTENT_ACLS) = 0 Then

CheckFileAccess = -1

Exit Function

End If

GetFileSecurity fileName, OWNER_SECURITY_INFORMATION Or GROUP_SECURITY_INFORMATION Or DACL_SECURITY_INFORMATION, 0, 0, SDSize

If Err.LastDllError 122 Then

CheckFileAccess = -1 'Rights not supported. Returning -1.

Exit Function

End If

If SDSize = 0 Then Exit Function

ReDim SecDesc(1 To SDSize)

If GetFileSecurity(fileName, OWNER_SECURITY_INFORMATION _

Or GROUP_SECURITY_INFORMATION _

Or DACL_SECURITY_INFORMATION, _

SecDesc(1), SDSize, SDSize) = 0 Then

Exit Function

End If

ImpersonateSelf SecurityImpersonation 'Adding Impersonation Token for thread

OpenThreadToken GetCurrentThread(), TOKEN_QUERY, 0, hToken 'Opening of Token of current thread

If hToken 0 Then

GenMap.GenericRead = FILE_GENERIC_READ

GenMap.GenericWrite = FILE_GENERIC_WRITE

GenMap.GenericExecute = FILE_GENERIC_EXECUTE

GenMap.GenericAll = FILE_ALL_ACCESS

MapGenericMask DesiredAccess, GenMap

AccessCheck SecDesc(1), hToken, DesiredAccess, GenMap, PrivSet, Len(PrivSet), CheckFileAccess, r

CloseHandle hToken

End If

RevertToSelf

End Function

以下为关联文档:

使用Eclipse插件FatJar做可执行的jar文件一个ja GUI的程序发现一个相当好的eclipse插件---FatJar: 这个插件的功能就是把外部导入的jar包和自己写的程序做成新的jar包,例如:我们可以直接把数据库驱动程序放到我们自己...

系统技巧:用WinHex找回消失的磁盘数据两个物理硬盘,主盘分了两个区,分别为一个C盘,一个E盘,所以把Guest这个软件放到第二个硬盘D盘的根目录下。重起进入DOS进入到软件的画面,不管三七二十一,玩玩再说。好奇的我直接选...

彻底巧妙解决文件无法删除当我们试图将一些无用的文件删除时,却常常并不如愿所偿。无法删除的文件的原因有很多,下面我们就向大家介绍常见的解决方法。 一、文件调用 被删除的文件正在被调用,这是无法删...

如何提高公路工程施工投标文件的质量1、创建良好的投标工作环境 投标单位的领导必须给予投标工作高度的重视,组建一支人员充足稳定、责任心强、政治素质好、业务水平高的编标队伍,并从资源配置(如电脑、扫描仪、各...

一种Linux下隐藏文件的新方法一. 概述 目前通用的隐藏文件方法还是hooksys_getdents64系统调用, 大致流程就是先调用原始的sys_getdents64系统调用,然后在在buf中做过滤。修改sys_call_table是比较原始的r...

批处理文件判断哪些IP地址Ping不通此文章主要针对内网来说事的,因为这个批处理文件针对的是某一网段循环ping而得出来的结果分析哪些IP地址Ping不通,以便让网管查询没有被占用的IP地址。 打开记事本,在窗口中输...

dos命令之formAT命令磁盘格式化命令formAT——磁盘格式化命令 1.功能:对磁盘进行格式化,划分磁道和扇区;同时检查出整个磁盘上有无带缺陷的磁道,对坏道加注标记;建立目录区和文件分配表,使磁盘作好接收DOS的准备。 2....

环评文件技术审查要点技术审查相关要求 1、评估中心将按照《程序》为各评价单位服务;(时间、预审和复核、加强现场) 2、为提高效率和更具针对性,评价单位按照审查要点汇报,中心组织专家按照审查要点审...

Structs2.0配置文件propertits详解struts.action.extension The URL extension to use to determine if the request is meant for a Struts action 用URL扩展名来确定是否这个请求是被用作Struts action,其实...

推荐阅读
图文推荐