| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 682 人关注过本帖
标题:[求助]模块调用的问题
只看楼主 加入收藏
宝贝学编程
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-8-26
收藏
 问题点数:0 回复次数:2 
[求助]模块调用的问题
'模块
---------------
Option Explicit

Private Declare Function InitializeAcl Lib "advapi32.dll" ( _
ByVal pAcl As Long, _
ByVal nAclLength As Long, _
ByVal dwAclRevision As Long) As Long
Private Type ACL
AclRevision As Byte
Sbz1 As Byte
AclSize As Integer
AceCount As Integer
Sbz2 As Integer
End Type

Private Declare Function AddAccessDeniedAce Lib "advapi32.dll" ( _
ByVal pAcl As Long, _
ByVal dwAceRevision As Long, _
ByVal AccessMask As Long, _
ByRef pSid As Any) As Long
Private Declare Function AddAccessAllowedAce Lib "advapi32.dll" ( _
ByVal pAcl As Long, _
ByVal dwAceRevision As Long, _
ByVal AccessMask As Long, _
ByRef pSid As Any) As Long
Private Enum SE_OBJECT_TYPE
SE_UNKNOWN_OBJECT_TYPE = 0
SE_FILE_OBJECT
SE_SERVICE
SE_PRINTER
SE_REGISTRY_KEY
SE_LMSHARE
SE_KERNEL_OBJECT
SE_WINDOW_OBJECT
SE_DS_OBJECT
SE_DS_OBJECT_ALL
SE_PROVIDER_DEFINED_OBJECT
SE_WMIGUID_OBJECT
End Enum

Private Declare Function SetSecurityInfo Lib "advapi32.dll" (ByVal Handle As Long, ByVal ObjectType As SE_OBJECT_TYPE, ByVal SecurityInfo As Long, ppsidOwner As Long, ppsidGroup As Long, ppDacl As Any, ppSacl As Any) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" ( _
ByVal hObject As Long) As Long
Private Declare Sub FreeSid Lib "advapi32.dll" ( _
ByRef pSid As Any)
Private Declare Function GetTokenInformation Lib "advapi32.dll" ( _
ByVal TokenHandle As Long, _
ByRef TokenInformationClass As Integer, _
ByRef TokenInformation As Any, _
ByVal TokenInformationLength As Long, _
ByRef ReturnLength As Long) As Long
Private Declare Function LocalAlloc Lib "kernel32.dll" ( _
ByVal wFlags As Long, _
ByVal wBytes As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" ( _
ByVal ProcessHandle As Long, _
ByVal DesiredAccess As Long, _
ByRef TokenHandle As Long) As Long
Private Declare Function AllocateAndInitializeSid Lib "advapi32.dll" ( _
ByRef pIdentifierAuthority As SID_IDENTIFIER_AUTHORITY, _
ByVal nSubAuthorityCount As Byte, _
ByVal nSubAuthority0 As Long, _
ByVal nSubAuthority1 As Long, _
ByVal nSubAuthority2 As Long, _
ByVal nSubAuthority3 As Long, _
ByVal nSubAuthority4 As Long, _
ByVal nSubAuthority5 As Long, _
ByVal nSubAuthority6 As Long, _
ByVal nSubAuthority7 As Long, _
ByRef lpPSid As Any) As Long
Private Type SID_IDENTIFIER_AUTHORITY
Value(6) As Byte
End Type
Private Const TOKEN_QUERY As Long = &H8
Private Const LMEM_FIXED As Long = &H0
Private Const LMEM_ZEROINIT As Long = &H40
Private Const LPTR As Long = (LMEM_FIXED + LMEM_ZEROINIT)
Private Const ACL_REVISION As Long = 2
Private Const DACL_SECURITY_INFORMATION As Long = &H4&
Private Const PROTECTED_DACL_SECURITY_INFORMATION As Long = (&H80000000)
Private Declare Function GetLastError Lib "kernel32.dll" () As Long
Private Type SID_AND_ATTRIBUTES
Sid As Long
Attributes As Long
End Type
Public Function DisableProcessAccess(ByVal hProcess As Long, ByVal dwAccessDenied As Long, ByVal dwAccessAllowed As Long) As Boolean
Dim sia As SID_IDENTIFIER_AUTHORITY
Dim pSid As Long 'psid
Dim bSuccess As Boolean
Dim buf(1 To &H400) As Byte
Dim buf1(1 To &H400) As Byte
Dim pTokenUser As Long 'pToken_User
Dim pAcl As Long 'pAcl
pAcl = VarPtr(buf(1))
Dim TokenInfo As Long
Dim hToken As Long
Dim dwRetLen As Long
Dim dw As Long
bSuccess = AllocateAndInitializeSid(sia, 1, 0, 0, 0, 0, 0, 0, 0, 0, ByVal VarPtr(pSid))
Debug.Print GetLastError

If (Not bSuccess) Then GoTo Cleanup
bSuccess = OpenProcessToken(hProcess, TOKEN_QUERY, ByVal VarPtr(hToken))
'Debug.Print GetLastError

If (Not bSuccess) Then GoTo Cleanup
Call GetTokenInformation(hToken, ByVal 1, ByVal 0, 0, dwRetLen)
'Debug.Print GetLastError
TokenInfo = VarPtr(buf1(1))
bSuccess = GetTokenInformation(hToken, ByVal 1, ByVal TokenInfo, dwRetLen, dw)
'Debug.Print GetLastError

If (Not bSuccess) Then GoTo Cleanup
bSuccess = InitializeAcl(pAcl, &H400, ACL_REVISION)
'Debug.Print GetLastError

If (Not bSuccess) Then GoTo Cleanup
bSuccess = AddAccessDeniedAce(pAcl, ACL_REVISION, dwAccessDenied, ByVal pSid)
'Debug.Print GetLastError

If (Not bSuccess) Then GoTo Cleanup
bSuccess = AddAccessAllowedAce(pAcl, ACL_REVISION, dwAccessAllowed, ByVal pSid)
'Debug.Print GetLastError

If (Not bSuccess) Then GoTo Cleanup
If (SetSecurityInfo(hProcess, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION Or PROTECTED_DACL_SECURITY_INFORMATION, ByVal 0, ByVal 0, ByVal pAcl, ByVal 0) = 0) Then bSuccess = True
Debug.Print GetLastError
Cleanup:
If (hProcess <> 0) Then CloseHandle (hProcess)
If (pSid <> 0) Then Call FreeSid(ByVal pSid)
DisableProcessAccess = bSuccess
End Function

在窗体上过程怎么写啊?
搜索更多相关主题的帖子: 模块 ACL Long Integer ByVal 
2007-10-01 09:49
宝贝学编程
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-8-26
收藏
得分:0 
我试了几次了,老是提示参数不对
call DisableProcessAccess()
老是错误,请问怎么解决?
2007-10-01 09:50
小小孩子
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-30
收藏
得分:0 
看晕了
2007-10-01 11:35
快速回复:[求助]模块调用的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015230 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved