全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2568
推到 Plurk!
推到 Facebook!

delphi 如何限制用户访问权限!

尚未結案
piaolingfeihu
一般會員


發表:7
回覆:12
積分:3
註冊:2007-06-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-06-05 10:42:03 IP:59.175.xxx.xxx 訂閱
请各位有时间的高手指点下,小弟想限制一个指定文件夹的访问权限。写了这样的一个小例程,但是运行却执行不好,请各位大大指点!

代码如下:
[code delphi]
procedure TForm1.Button1Click(Sender: TObject);
var
SD: SECURITY_DESCRIPTOR;
pUserSID, pGroupSID: Pointer;
szDomain: PChar;
snuType: SID_NAME_USE;
cbSID: DWORD;
cbDomain: DWORD;
begin
if InitializeSecurityDescriptor(@SD, SECURITY_DESCRIPTOR_REVISION) then
ShowMessage('Initialize ok')
else
ShowMessage('Initialize failed');
cbDomain := 80;
cbSID := 1024;
pUserSID := AllocMem(cbSID);
szDomain := AllocMem(cbDomain);
if LookupAccountName(nil, 'administrator', pUserSID, cbSID, szDomain, cbDomain, snuType) then
ShowMessage('LookupAccountName:User ok')
else
ShowMessage('LookupAccountName:User failed');
if SetSecurityDescriptorOwner(@SD, pUserSID, False) then
ShowMessage('SetSecurityOwner:User ok')
else
ShowMessage('SetSecurityOwner:User failed');
cbDomain := 80;
cbSID := 1024;
pGroupSID := AllocMem(cbSID);
szDomain := AllocMem(cbDomain);
if LookupAccountName(nil, 'Administrators', pGroupSID, cbSID, szDomain, cbDomain, snuType) then
ShowMessage('LookupAccountName:Group ok')
else
ShowMessage('LookupAccountName:Group failed');
if SetSecurityDescriptorGroup(@SD, pGroupSID, False) then
ShowMessage('SetSecurityGroup ok')
else
ShowMessage('SetSecurityGroup failed');
// ShowMessage(IntToStr(OWNER_SECURITY_INFORMATION or GROUP_SECURITY_INFORMATION));
if SetFileSecurity('D:\temp2', OWNER_SECURITY_INFORMATION or GROUP_SECURITY_INFORMATION, @SD) then
ShowMessage('SetFileSecurity ok')
else
ShowMessage('SetFileSecurity failed');
end;
[/code]

限制“d:\temp2”的用户访问权限!

谢谢,小弟再次感激不尽!

------
没有做不到,只有想不到!
編輯記錄
piaolingfeihu 重新編輯於 2008-06-05 10:48:22, 註解 無‧
yckuo 重新編輯於 2008-06-06 13:49:26, 註解 修改不當標題,套用程式碼高亮顯示.‧
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-06-21 08:51:30 IP:220.246.xxx.xxx 訂閱
這問題應屬Win32API而不是VCL,所以幫你移動到Win32API版,望能得到相關高手回覆。
系統時間:2024-04-26 22:09:43
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!