代码中一开始的 几个 USES 单元,可能是多余的。

unit ShareRestrictedSD;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Shlobj, ActiveX, Dialogs,Shellapi; ///////////////////
//如果这家伙起作用,那么它的作者是jiangsheng(C++);
//如果这家伙一点用没有,那我不知道它的作者
//以上为 jiangsheng 的声明.
//使用方法.
//var
// SharedSD:TShareRestrictedSD; //创建一个工具类.
// try
// SharedSD:=TShareRestrictedSD.Create;
// FMappingHandle :=
// CreateFileMapping(
// $FFFFFFFF, {to virtual memory}
// SharedSD.GetSA, //获得一个超级用户安全对象.
// page_readwrite,
// ,
// FSize,
// pchar(FNameToCreate));
// finally
// if (SharedSD <> nil) then
// begin
// FreeAndNil(SharedSD); //一定要记得释放
// end;
// end;
//修改:Flying Wang 和 爱吃猪头肉
/////////////////// const
SECURITY_NULL_SID_AUTHORITY = $;
SECURITY_WORLD_SID_AUTHORITY = $;
SECURITY_LOCAL_SID_AUTHORITY = $;
SECURITY_CREATOR_SID_AUTHORITY = $;
SECURITY_NT_AUTHORITY = $; ACL_REVISION = $; SECURITY_NULL_RID = $;
SECURITY_LOCAL_RID = $;
SECURITY_WORLD_RID = $;
SECURITY_CREATOR_OWNER_RID = $;
SECURITY_DIALUP_RID = $;
SECURITY_CREATOR_GROUP_RID = $;
SECURITY_NETWORK_RID = $;
SECURITY_BATCH_RID = $;
SECURITY_INTERACTIVE_RID = $;
SECURITY_LOGON_IDS_RID = $;
SECURITY_SERVICE_RID = $;
SECURITY_LOCAL_SYSTEM_RID =$;
SECURITY_BUILTIN_DOMAIN_RID =$; HEAP_NO_SERIALIZE = $;
HEAP_GROWABLE = $;
HEAP_GENERATE_EXCEPTIONS = $;
HEAP_ZERO_MEMORY = $;
HEAP_REALLOC_IN_PLACE_ONLY =$;
HEAP_TAG_SHIFT =$;
HEAP_TAIL_CHECKING_ENABLED =$;
HEAP_FREE_CHECKING_ENABLED =$;
HEAP_DISABLE_COALESCE_ON_FREE =$;
HEAP_MAXIMUM_TAG =$0FFF;
HEAP_PSEUDO_TAG_FLAG =$;
HEAP_CREATE_ALIGN_ =$;
HEAP_CREATE_ENABLE_TRACING =$; type PACE_HEADER = ^TACE_HEADER;
_ACE_HEADER = record
AceType:Byte;
AceFlags:Byte;
AceSize:Word;
end;
TACE_HEADER = _ACE_HEADER;
ACE_HEADER = _ACE_HEADER; // ACCESS_MASK = DWORD; PACCESS_ALLOWED_ACE = ^TACCESS_ALLOWED_ACE;
_ACCESS_ALLOWED_ACE = record
Header:TACE_HEADER;
Mask:ACCESS_MASK;
SidStart:DWORD;
end;
TACCESS_ALLOWED_ACE = _ACCESS_ALLOWED_ACE;
ACCESS_ALLOWED_ACE = _ACCESS_ALLOWED_ACE; TShareRestrictedSD =class(TObject)
private
{ Private-Deklarationen }
ptr:Pointer;
sa:TSecurityAttributes;
sd:TSecurityDescriptor;
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
Constructor Create;
Destructor Destroy; override;
function GetSA:PSecurityAttributes;
published
{ Published-Deklarationen }
end; implementation Const
DefSubAuthorityCount = ; Function BuildRestrictedSD(pSD: PSecurityDescriptor): Pointer;
var
dwAclLength: DWORD;
psideveryone: PSID;
pDACL: PACL;
bResult: Boolean;
pACE: PACCESS_ALLOWED_ACE;
siaWorld: TSIDIdentifierAuthority;
si: SECURITY_INFORMATION;
begin
Result := nil;
psideveryone := nil;
pDACL := nil;
bResult := False;
pACE := nil;
FillMemory(@siaWorld,Sizeof(siaWorld),SECURITY_NULL_SID_AUTHORITY);
siaWorld.Value[]:=SECURITY_WORLD_SID_AUTHORITY;
si := DACL_SECURITY_INFORMATION;
try
// initialize the security descriptor
if (not InitializeSecurityDescriptor(pSD,
SECURITY_DESCRIPTOR_REVISION)) then
begin
//InitializeSecurityDescriptor() failed;
exit;
end;
// obtain a sid for the Authenticated Users Group
if (not AllocateAndInitializeSid(siaWorld,
DefSubAuthorityCount,
SECURITY_WORLD_RID,
SECURITY_NULL_RID,
SECURITY_NULL_RID,
SECURITY_NULL_RID,
SECURITY_NULL_RID,
SECURITY_NULL_RID,
SECURITY_NULL_RID,
SECURITY_NULL_RID,
psidEveryone)) then
begin
//AllocateAndInitializeSid() failed;
exit;
end;
// NOTE:
//
// The Authenticated Users group includes all user accounts that
// have been successfully authenticated by the system. If access
// must be restricted to a specific user or group other than
// Authenticated Users, the SID can be constructed using the
// LookupAccountSid() API based on a user or group name. // calculate the DACL length
dwAclLength := sizeof(ACL)
// add space for Authenticated Users group ACE
+ sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)
+ GetLengthSid(psidEveryone);
// allocate memory for the DACL
pDACL := PACL(HeapAlloc(GetProcessHeap, HEAP_ZERO_MEMORY,
dwAclLength));
if (pDACL = nil) then
begin
//HeapAlloc() failed;
exit;
end;
// initialize the DACL
if (not InitializeAcl(pDACL^, dwAclLength, ACL_REVISION)) then
begin
//InitializeAcl() failed
exit;
end;
// add the Authenticated Users group ACE to the DACL with
// GENERIC_READ, GENERIC_WRITE, and GENERIC_EXECUTE access
if (not AddAccessAllowedAce(pDACL^, ACL_REVISION,
GENERIC_ALL,
psidEveryone)) then
begin
//AddAccessAllowedAce() failed;
exit;
end;
// set the DACL in the security descriptor
if (not SetSecurityDescriptorDacl(pSD, TRUE, pDACL, FALSE)) then
begin
//SetSecurityDescriptorDacl() failed;
exit;
end;
bResult := True;
finally
if (psidEveryone <> nil) then
begin
FreeSid(psidEveryone);
end;
if (not bResult) then
begin
if (pDACL <> nil) then
begin
HeapFree(GetProcessHeap, , pDACL);
end;
pDACL := nil;
end;
end;
Result := pDACL;
end; //The following function frees memory allocated in the
// BuildRestrictedSD() function
procedure FreeRestrictedSD(ptr: Pointer);
begin
if (ptr <> nil) then
begin
HeapFree(GetProcessHeap, , ptr);
end;
end; Constructor TShareRestrictedSD.Create;
begin
ptr := nil;
sa.nLength := Sizeof(sa);
sa.lpSecurityDescriptor := @Sd;
sa.bInheritHandle := False;
// build a restricted security descriptor
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
ptr := BuildRestrictedSD(@sd);
if (ptr = nil) then
begin
Raise Exception.Create('BuildRestrictedSD failed');
end;
end;
end; Destructor TShareRestrictedSD.Destroy;
begin
if (ptr <> nil) then
begin
FreeRestrictedSD(ptr);
end;
end; function TShareRestrictedSD.GetSA:PSecurityAttributes;
begin
if (ptr <> nil) then
begin
Result := @Sa;
end
else
begin
Result := nil;
end;
end; end.

很久以前写的一个 ShareRestrictedSD 类的更多相关文章

  1. 用C#写的一个OA类的APP, ios、Android都能跑,有源代码

    这是一个用C#写的OA类APP,功能包含请假.报销.部门管理.签到.IM.文件上传等功能 话不多说,先看视频 视频地址:http://v.youku.com/v_show/id_XMzUwMjQ1Mz ...

  2. 收集C#常用类:自己写的一个DBHelper类

    随着学的东西越来越多,一点点的完善吧! using System; using System.Collections.Generic; using System.Linq; using System. ...

  3. 写的一个HttpClient类

    package com.ca.test.cainterface.common.util.http; import com.ca.test.cainterface.common.util.data.Da ...

  4. 使用代码向一个普通的类注入Spring的实例

    转载请在页首注明作者与原文地址 一:应用场景 什么是普通的类,就是没有@Controller,@Service,@Repository,@Component等注解修饰的类,同时xml文件中,也没有相应 ...

  5. Java基础-继承-编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight。小车类Car是Vehicle的子类,其中包含的属性有载人数 loader。卡车类Truck是Car类的子类,其中包含的属性有载重量payload。每个 类都有构造方法和输出相关数据的方法。最后,写一个测试类来测试这些类的功 能。

    #29.编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight.小车类Car是Vehicle的子类,其中包含的属性有载人数 loader.卡车类T ...

  6. 我写的一个ExcelHelper通用类,可用于读取或生成数据

    读取或生成EXCEL数据的方法有很多,一般常见的有: 1.通过OFFICE EXCEL组件,优点:读取与生成EXCEL文件方便,缺点:服务器上必须安装OFFICE软件,且进程无法及时释放 2.通过第三 ...

  7. 我写了一个java实体类,implements了Serializable接口,然后我如何让serialversionUID自动生成

    写了一个java实体类,implements了Serializable接口,让serialversionUID自动生成方法: 1.点击类旁边的警告符号: 2.选择Add generated seria ...

  8. 编程写一个方法时,注意方法中传参数的数量最好不要超过5个,超过5个怎么办?可以用struct或class,或一个字典类

    图  1 一.从图1发现了什么问题呢? 答案:1.参数传的的太多了:2.另外注释也没写好. 说明:一个方法中,传参数的数量最好不要超过5个. 应该采用:struct或class,或一个字典类都行.其中 ...

  9. 封装一个帮助类来写文件到android外置存储器上

    项目地址:点击打开 项目简介:写文件到android外置存储器的一个帮助类,和它的demo程序 它是如何工作的呢? 1.创建 AppExternalFileWriter 对象并传递context(上下 ...

随机推荐

  1. 【Raspberry Pi】新入手的Raspberry Pi3拼装日志

    一.概述 2016年暑假某宝入手Raspberry Pi 3,装机清单: 树莓派主板 亚克力外壳 小风扇 散热片 30G SD card 螺丝若干颗 因机型问题,可能与你的机器有微小差异 二.装机过程 ...

  2. [LintCode] Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...

  3. 在火狐、360等浏览器中,用jquery创建表单并发送的问题

    某些浏览器无法使用js或者jquery直接创建表单并发送,这是由于这些浏览器在提交页面表单时要求页面有完整的标签项即<html><head><title></ ...

  4. log4j详解(二)

    在实际编程时,要使Log4j真正在系统中运行事先还要对配置文件进行定义.定义步骤就是对Logger.Appender及Layout的分别使用.Log4j支持两种配置文件格式,一种是XML格式的文件,一 ...

  5. webservice总结

    webservice xml(DTD,Schema,Stax) SOAP jax-ws (java api xml webservice) 契约优先的开发模式 CXF Rest 异构平台之间的交互(. ...

  6. 实战java虚拟机的学习计划图(看懂java虚拟机)

    啥也不说了,实战java虚拟机,好好学习,天天向上!针对自己的软肋制定学习计划. 一部分内容看完,自己做的学习笔记和感想. 学java很简单,但懂java会有难度,如果你的工资还没超过1W,那是时候深 ...

  7. PHP的变量

    1.可变变量 一个变量的变量名可以动态地设置和使用.一个普通的变量通过声明来设置,而一个可变变量获取了一个普通变量的值作为这个可变变量的变量名,如下所示: <?php $hi = "h ...

  8. Ubuntu ./configure 半途终止 导致没有生成makefile文件 解决方法

    在安装thrift的时候,解压包进入目录,执行命令: ./configure 之后,发现某些包没有安装,导致configure到一半的时候退出,接着make发现没有makefile文件.估计是我系统安 ...

  9. 刷新本地的DNS缓存数据

    ipconfig /flushdns”执行,刷新本地的DNS缓存数据. ipconfig /displaydns      查看本地DNS缓存记录的命令为:ipconfig /displaydns.你 ...

  10. C#.NET中数组、ArrayList和List三者的区别

    数组在C#.NET中是最早出现的,在内存中是顺序连续存储的,所以它的索引速度非常快,赋值与修改元素也很简单:但是,也正因为数组是顺序连续存储的,在两个数据间插入数据是很不方便的,而且在声明数组的时候必 ...