線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1867
推到 Plurk!
推到 Facebook!

如何偵測資料夾存取權限?

尚未結案
MingLin
一般會員


發表:24
回覆:26
積分:10
註冊:2002-09-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-16 11:00:38 IP:220.130.xxx.xxx 未訂閱
在我的電腦要如何偵測位於網路芳鄰上某一個資料夾的存取權限呢?因為要避開"File Access Denied"錯誤訊息。謝謝!
aquarius
資深會員


發表:3
回覆:347
積分:330
註冊:2003-05-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-16 18:25:40 IP:211.23.xxx.xxx 未訂閱
引言: 在我的電腦要如何偵測位於網路芳鄰上某一個資料夾的存取權限呢?因為要避開"File Access Denied"錯誤訊息。謝謝!
提供兩個FUNCTION GetFileSecurity GetFileAttributes 前者是用來區分使用者的存取權限, 後者是一般的檔案屬性(例如唯讀, 系統...) 看你問的問題, 應該是要用 GetFileSecurity ...Aquarius
------
水瓶男的blog: http://791909.blogspot.com
MingLin
一般會員


發表:24
回覆:26
積分:10
註冊:2002-09-20

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-17 08:24:11 IP:220.130.xxx.xxx 未訂閱
GetFileAttribute已試過但無法做到 GetFileSecurity因無法找到相關範例,故未測試。請幫忙提供相關範例,謝謝!
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-17 10:28:47 IP:220.131.xxx.xxx 未訂閱
http://www.delphitips.com/tipstext.cgi?tipsId=73
// When you create a file or directory, you become the owner of it. 
// With GetFileOwner you get the owner of a file.     function GetFileOwner(FileName: string; 
var Domain, Username: string): Boolean; 
var 
  SecDescr: PSecurityDescriptor; 
  SizeNeeded, SizeNeeded2: DWORD; 
  OwnerSID: PSID; 
  OwnerDefault: BOOL; 
  OwnerName, DomainName: PChar; 
  OwnerType: SID_NAME_USE; 
begin 
  GetFileOwner := False; 
  GetMem(SecDescr,1024); 
  GetMem(OwnerSID,SizeOf(PSID)); 
  GetMem(OwnerName,1024); 
  GetMem(DomainName,1024); 
  try 
   if not GetFileSecurity(PChar(FileName), 
   OWNER_SECURITY_INFORMATION, 
   SecDescr,1024,SizeNeeded) then 
   Exit; 
   if not GetSecurityDescriptorOwner(SecDescr, 
   OwnerSID,OwnerDefault) then 
    Exit; 
    SizeNeeded := 1024; 
   SizeNeeded2 := 1024; 
   if not LookupAccountSID(nil,OwnerSID,OwnerName, 
     SizeNeeded,DomainName,SizeNeeded2,OwnerType) then 
     Exit; 
     Domain := DomainName; 
     Username := OwnerName; 
   finally 
     FreeMem(SecDescr); 
     FreeMem(OwnerName); 
     FreeMem(DomainName); 
   end; 
  GetFileOwner := True; 
end;     procedure TForm1.Button1Click(Sender: TObject); 
var 
  Domain, Username: string; 
begin 
  GetFileOwner('YourFile.xyz',domain,username); 
  ShowMessage(username   '@'   domain); 
end; 
 
網海無涯,唯學是岸! 因為擁有,所以分享!
MingLin
一般會員


發表:24
回覆:26
積分:10
註冊:2002-09-20

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-11-18 08:32:43 IP:220.130.xxx.xxx 未訂閱
雖然讀了上面的範例,還是覺得這個主題對我而言實在有些艱澀難懂,有相關書籍或文章專門介紹這個主題的嗎?謝謝!
aquarius
資深會員


發表:3
回覆:347
積分:330
註冊:2003-05-21

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-11-18 12:27:47 IP:211.23.xxx.xxx 未訂閱
引言: 雖然讀了上面的範例,還是覺得這個主題對我而言實在有些艱澀難懂,有相關書籍或文章專門介紹這個主題的嗎?謝謝!
MSDN 的說明很詳細. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/getfilesecurity.asp ...Aquarius
------
水瓶男的blog: http://791909.blogspot.com
系統時間:2024-05-14 17:22:46
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!