delphi 如何限制用户访问权限! |
尚未結案
|
piaolingfeihu
一般會員 發表:7 回覆:12 積分:3 註冊:2007-06-07 發送簡訊給我 |
请各位有时间的高手指点下,小弟想限制一个指定文件夹的访问权限。写了这样的一个小例程,但是运行却执行不好,请各位大大指点!
代码如下: [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 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |