':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ' VB6实现枚举进程所拥有的特权 ' Programmed by 魏滔序 ' WebSite: http://www.chenoe.com ' Blog: http://blog.csdn.net/Modest '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: OptionExplicit PrivateConst ANYSIZE_ARRAY AsLong=100 PrivateConst TokenPrivileges =3 PrivateConst TOKEN_QUERY =&H8 Private Type LUID lowpart AsLong highpart AsLong End Type Private Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes AsLong End Type Private Type TOKEN_PRIVILEGES PrivilegeCount AsLong Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES End Type PrivateDeclareFunction GetCurrentProcess()Function GetCurrentProcess Lib"kernel32" () AsLong PrivateDeclareFunction OpenProcessToken()Function OpenProcessToken Lib"Advapi32" (ByVal ProcessHandle AsLong, ByVal DesiredAccess AsLong, TokenHandle AsLong) AsLong PrivateDeclareFunction GetTokenInformation()Function GetTokenInformation Lib"Advapi32" (ByVal TokenHandle AsLong, TokenInformationClass AsInteger, TokenInformation As Any, ByVal TokenInformationLength AsLong, ReturnLength AsLong) AsLong PrivateDeclareFunction RtlMoveMemory()Function RtlMoveMemory Lib"kernel32" (Dest As Any, Source As Any, ByVal lSize AsLong) AsLong PrivateDeclareFunction CloseHandle()Function CloseHandle Lib"kernel32" (ByVal hObject AsLong) AsLong PrivateFunction GetProcressPrivileges()Function GetProcressPrivileges(ByVal hProcess AsLong) AsLong() Dim hToken AsLong Dim BufferSize AsLong Dim InfoBuffer() AsLong Dim i AsLong, r() AsLong, x AsLong Dim lResult AsLong Dim tpTokens As TOKEN_PRIVILEGES Call OpenProcessToken(hProcess, TOKEN_QUERY, hToken) If hToken Then Call GetTokenInformation(hToken, ByVal TokenPrivileges, 0, 0, BufferSize) If BufferSize Then ReDim InfoBuffer((BufferSize 4) -1) AsLong lResult = GetTokenInformation(hToken, ByVal TokenPrivileges, InfoBuffer(0), BufferSize, BufferSize) If lResult =1Then Call RtlMoveMemory(tpTokens, InfoBuffer(0), LenB(tpTokens)) For i =0To tpTokens.PrivilegeCount -1 If tpTokens.Privileges(i).Attributes <>0Then ReDimPreserve r(x) r(x) = tpTokens.Privileges(i).pLuid.lowpart x = x +1 EndIf Next EndIf EndIf Call CloseHandle(hToken) EndIf GetProcressPrivileges = r End Function '示例代码 PrivateSub Form_Load()Sub Form_Load() Dim p() AsLong, i AsLong p = GetProcressPrivileges(GetCurrentProcess) For i =0ToUBound(p) Debug.Print p(i) Next End Sub