NetShareGetInfo的使用问题(100分)

  • 主题发起人 主题发起人 lonelybug
  • 开始时间 开始时间
L

lonelybug

Unregistered / Unconfirmed
GUEST, unregistred user!
我用NetShareGetInfo来获得指定的文件加的目录共享的相应的数据,可是<br>NetShareGetInfo(nil,PWideChar(Sharpaths),2,@si)这样子取得的数据都位空的也就是说<br>si.shi2_remark<br>si.shi2_netname<br>这两个值都是空的,我像问问如何解决,或者能不能告诉我如何使用!
 
你的操作系统是什么?
 
win2k 和win98<br>谢谢
 
function Tform1.GetShareAttr(Sharepath:string):string;<br>type<br>TShare_INFO_2 = record<br>&nbsp; &nbsp; shi2_netname : PWideChar;<br>&nbsp; &nbsp; shi2_type : DWORD;<br>&nbsp; &nbsp; shi2_remark : PWideChar;<br>&nbsp; &nbsp; shi2_permissions : DWORD;<br>&nbsp; &nbsp; shi2_max_uses : DWORD;<br>&nbsp; &nbsp; shi2_current_uses : DWORD;<br>&nbsp; &nbsp; shi2_path : PWideChar;<br>&nbsp; &nbsp; shi2_passwd : PWideChar;<br>&nbsp; &nbsp; end;<br>var<br>&nbsp; Shareattrstr:widestring;<br>&nbsp; remark,netname:string;<br>&nbsp; Sharpaths:widestring;<br>&nbsp; shareAttrresult,shareAttrtemp:string;<br>&nbsp; i:longint;<br>&nbsp; si: TShare_INFO_2;<br>&nbsp; NetShareGetInfo:TNetShareGetInfo;<br>&nbsp; Fpointer:TfarProc;<br>begin<br>&nbsp; Fpointer:=GetProcAddress(hinstDLL,'NetShareGetInfo');<br>&nbsp; if Fpointer=nil then<br>&nbsp; &nbsp; raise exception.Create ('GetNetSharInfo not found!');<br>&nbsp; NetShareGetInfo:=TNetShareGetInfo(Fpointer);<br>&nbsp; Sharpaths:=Sharepath;<br>&nbsp; NetShareGetInfo(nil',pwidechar(Sharpaths)',2,@si);<br>&nbsp; remark:=si.shi2_remark;<br>&nbsp; netname:=si.shi2_netname;<br>&nbsp; <br>&nbsp; showmessage(netname+','+remark+','+inttostr(si.shi2_current_uses));<br>&nbsp; GetShareAttr:=netname+','+remark+','+inttostr(si.shi2_current_uses);<br>end;<br>这是我的程序,请帮我看看,为什么si.shi2_remark的值,还有其它的总是空的,还有一个问题就是用sharenetadd来设目录位共享的时候,把shi2_permissions 设置为read_only的时候系统说read_only没有定义,他不是一个数字型的参数码,怎么回事,我看了一些c++里面用的方法就可以!百思不得其节,请各位高手赐教!<br>
 
help me<br>
 
转贴:)<br>const <br>&nbsp; ACL_REVISION = 2; <br>&nbsp; ACL_REVISION2 = 2; <br>&nbsp; netapi32lib = 'Netapi32.dll'; <br><br>Type <br>&nbsp; NET_API_STATUS = Integer; <br><br>&nbsp; PShare_Info_502 = ^TShare_Info_502; <br>&nbsp; TShare_Info_502 = record <br>&nbsp; &nbsp; shi502_netName: PWideChar; <br>&nbsp; &nbsp; shi502_type: DWORD; <br>&nbsp; &nbsp; shi502_remark: PWideChar; <br>&nbsp; &nbsp; shi502_permissions: DWORD; <br>&nbsp; &nbsp; shi502_max_uses: DWORD; <br>&nbsp; &nbsp; shi502_current_uses : DWORD; <br>&nbsp; &nbsp; shi502_path: PWideChar; <br>&nbsp; &nbsp; shi502_passwd: PWideChar; <br>&nbsp; &nbsp; shi502_reserved: DWORD; <br>&nbsp; &nbsp; shi502_security_descriptor: PSECURITY_DESCRIPTOR; <br>&nbsp; end; <br><br>&nbsp; ACE_HEADER = record <br>&nbsp; &nbsp; AceType: Byte; <br>&nbsp; &nbsp; AceFlags: Byte; <br>&nbsp; &nbsp; AceSize: Word; <br>&nbsp; end; <br><br>&nbsp; ACCESS_ALLOWED_ACE = record <br>&nbsp; &nbsp; Header:ACE_HEADER; <br>&nbsp; &nbsp; Mask:ACCESS_MASK; <br>&nbsp; &nbsp; SidStart:DWORD; <br>&nbsp; end; <br><br>&nbsp; ACL_SIZE_INFORMATION = record <br>&nbsp; &nbsp; AceCount: DWORD; <br>&nbsp; &nbsp; AclBytesInUse: DWORD; <br>&nbsp; &nbsp; AclBytesFree: DWORD; <br>&nbsp; end; <br><br>&nbsp; PACE_HEADER = ^ACE_HEADER; <br><br>function NetApiBufferFree(Buffer: Pointer): NET_API_STATUS; stdcall external netapi32lib; <br>function NetShareGetInfo(servername: LPWSTR; netname: LPWSTR; level: DWORD; <br>&nbsp; &nbsp; var butptr: Pointer): NET_API_STATUS; stdcall; external netapi32lib; <br>function NetShareSetInfo(servername: LPWSTR; netname: LPWSTR; leve: DWORD; <br>&nbsp; &nbsp;const buf: Pointer; parm_err: PDWORD): NET_API_STATUS; stdcall; external netapi32lib; <br><br>//添加文件、目录访问权限,对应于对象属性页中"安全" 页中的设置 <br>function AddFileAccesRights(const FileName, UserName: string; <br>&nbsp; dwAccessMask: DWORD): boolean; <br>var <br>&nbsp; // SID variables <br>&nbsp; snuType : SID_NAME_USE; <br>&nbsp; szDomain : PChar; <br>&nbsp; cbDomain: DWORD; <br>&nbsp; pUserSID: Pointer; <br>&nbsp; cbUserSID: DWORD; <br>&nbsp; // File SD variables. <br>&nbsp; pFileSD: PSECURITY_DESCRIPTOR; <br>&nbsp; cbFileSD: DWORD; <br>&nbsp; // New SD variables. <br>&nbsp; pNewSD: PSECURITY_DESCRIPTOR; <br>&nbsp; // ACL variables. <br>&nbsp; p_ACL : PACL; <br>&nbsp; fDaclPresent, fDaclDefaulted : LongBool; <br>&nbsp; AclInfo: ACL_SIZE_INFORMATION; <br>&nbsp; // New ACL variables. <br>&nbsp; pNewACL : PACL; <br>&nbsp; cbNewACL: DWORD; <br>&nbsp; // Temporary ACE. <br>&nbsp; pTempAce: Pointer; <br>&nbsp; CurrentAceIndex : Cardinal; <br>begin <br>&nbsp; szDomain := nil; <br>&nbsp; cbDomain := 0; <br>&nbsp; pUserSID := nil; <br>&nbsp; cbUserSID := 0; <br>&nbsp; pFileSD := nil; <br>&nbsp; cbFileSD := 0; <br>&nbsp; pNewSD := nil; <br>&nbsp; p_ACL := nil; <br>&nbsp; pNewACL := nil; <br>&nbsp; pTempAce := nil; <br><br>&nbsp; // <br>&nbsp; // STEP 1: Get SID for given user. <br>&nbsp; // <br>&nbsp; Result := LookupAccountName(nil, PChar(UserName), <br>&nbsp; &nbsp; pUserSID, cbUserSID, szDomain, cbDomain, snuType); <br><br>&nbsp; // API should have failed with insufficient buffer. <br>&nbsp; if (not Result) and (GetLastError &lt;&gt; ERROR_INSUFFICIENT_BUFFER) then <br>&nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; pUserSID := AllocMem(cbUserSID); <br>&nbsp; szDomain := AllocMem(cbDomain); <br>&nbsp; try <br>&nbsp; &nbsp; Result := LookupAccountName(nil, PChar(UserName), <br>&nbsp; &nbsp; &nbsp; &nbsp;pUserSID, cbUserSID, szDomain, cbDomain, snuType); <br><br>&nbsp; &nbsp; if (not Result) then <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; // STEP 2: Get security descriptor (SD) for file. <br>&nbsp; &nbsp; Result := GetFileSecurity(PChar(FileName), <br>&nbsp; &nbsp; &nbsp; DACL_SECURITY_INFORMATION, pFileSD, 0, cbFileSD); <br><br>&nbsp; &nbsp; if (not Result) and (GetLastError &lt;&gt; ERROR_INSUFFICIENT_BUFFER) then <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; pFileSD := AllocMem(cbFileSD); <br><br>&nbsp; &nbsp; Result := GetFileSecurity(PChar(FileName), <br>&nbsp; &nbsp; &nbsp; DACL_SECURITY_INFORMATION, pFileSD, cbFileSD, cbFileSD); <br>&nbsp; &nbsp; if (not Result) then <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; // STEP 3: Initialize new SD. <br>&nbsp; &nbsp; pNewSD := AllocMem(cbFileSD); // Should be same size as FileSD. <br><br>&nbsp; &nbsp; if (not InitializeSecurityDescriptor(pNewSD, <br>&nbsp; &nbsp; &nbsp; SECURITY_DESCRIPTOR_REVISION)) then <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; // STEP 4: Get DACL from SD. <br>&nbsp; &nbsp; if (not GetSecurityDescriptorDacl(pFileSD, fDaclPresent, p_ACL, <br>&nbsp; &nbsp; &nbsp; fDaclDefaulted)) then <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; // STEP 5: Get size information for DACL. <br>&nbsp; &nbsp; AclInfo.AceCount := 0; // Assume NULL DACL. <br>&nbsp; &nbsp; AclInfo.AclBytesFree := 0; <br>&nbsp; &nbsp; AclInfo.AclBytesInUse := SizeOf(ACL); <br><br>&nbsp; &nbsp; if (fDaclPresent and Assigned(p_ACL)) then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; if (not GetAclInformation(p_ACL^, @AclInfo, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SizeOf(ACL_SIZE_INFORMATION), AclSizeInformation)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; &nbsp; // STEP 6: Compute size needed for the new ACL. <br>&nbsp; &nbsp; &nbsp; cbNewACL := AclInfo.AclBytesInUse + SizeOf(ACCESS_ALLOWED_ACE) <br>&nbsp; &nbsp; &nbsp; &nbsp; + GetLengthSid(pUserSID) - SizeOf(DWORD); <br><br>&nbsp; &nbsp; &nbsp; // STEP 7: Allocate memory for new ACL. <br>&nbsp; &nbsp; &nbsp; pNewACL := AllocMem(cbNewACL); <br><br>&nbsp; &nbsp; &nbsp; // STEP 8: Initialize the new ACL. <br>&nbsp; &nbsp; &nbsp; if (not InitializeAcl(pNewACL^, cbNewACL, ACL_REVISION2)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; &nbsp; // STEP 9: If DACL is present, copy it to a new DACL. <br>&nbsp; &nbsp; &nbsp; if (fDaclPresent) then <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; // STEP 10: Copy the file's ACEs to the new ACL. <br>&nbsp; &nbsp; &nbsp; &nbsp; if (AclInfo.AceCount &gt; 0) then <br>&nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for CurrentAceIndex := 0 to AclInfo.AceCount - 1 do <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // STEP 11: Get an ACE. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not GetAce(p_ACL^, CurrentAceIndex, pTempAce)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // STEP 12: Add the ACE to the new ACL. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not AddAce(pNewACL^, ACL_REVISION, MAXDWORD, pTempAce, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PACE_HEADER(pTempAce)^.AceSize)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; end; <br><br>&nbsp; &nbsp; &nbsp; // STEP 13: Add the access-allowed ACE to the new DACL. <br>&nbsp; &nbsp; &nbsp; if (not AddAccessAllowedAce(pNewACL^, ACL_REVISION2, dwAccessMask, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pUserSID)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; &nbsp; // STEP 14: Set the new DACL to the file SD. <br>&nbsp; &nbsp; &nbsp; if (not SetSecurityDescriptorDacl(pNewSD, True, pNewACL, False)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; &nbsp; // STEP 15: Set the SD to the File. <br>&nbsp; &nbsp; &nbsp; if (not SetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pNewSD)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; &nbsp; Result := True; <br>&nbsp; &nbsp; end; <br>&nbsp; finally <br>&nbsp; &nbsp; // STEP 16: Free allocated memory <br>&nbsp; &nbsp; if Assigned(pUserSID) then <br>&nbsp; &nbsp; &nbsp; FreeMem(pUserSID); <br>&nbsp; &nbsp; if Assigned(szDomain) then <br>&nbsp; &nbsp; &nbsp; FreeMem(szDomain); <br>&nbsp; &nbsp; if Assigned(pFileSD) then <br>&nbsp; &nbsp; &nbsp; FreeMem(pFileSD); <br>&nbsp; &nbsp; if Assigned(pNewSD) then <br>&nbsp; &nbsp; &nbsp; FreeMem(pNewSD); <br>&nbsp; &nbsp; if Assigned(pNewACL) then <br>&nbsp; &nbsp; &nbsp; FreeMem(pNewACL); <br>&nbsp; end; <br>end; <br>//添加共享资源的访问权限,对应于对象属性页中"共享" 页中的设置,注意 ShareName <br>//对应的资源应已被设置为共享。这可以通过 NetShareAdd API 设置 <br>function AddShareAccesRights(const ShareName: WideString; <br>&nbsp; const UserName: string; dwAccessMask: DWORD): boolean; <br>var <br>&nbsp; // SID variables <br>&nbsp; snuType : SID_NAME_USE; <br>&nbsp; szDomain : PChar; <br>&nbsp; cbDomain: DWORD; <br>&nbsp; pUserSID: Pointer; <br>&nbsp; cbUserSID: DWORD; <br>&nbsp; // File SD variables. <br>&nbsp; pShareSD: PSECURITY_DESCRIPTOR; <br>&nbsp; // New SD variables. <br>&nbsp; pNewSD: PSECURITY_DESCRIPTOR; <br>&nbsp; // ACL variables. <br>&nbsp; p_ACL : PACL; <br>&nbsp; fDaclPresent, fDaclDefaulted : LongBool; <br>&nbsp; AclInfo: ACL_SIZE_INFORMATION; <br>&nbsp; //Share_Info variables <br>&nbsp; BufPtr: PShare_Info_502; <br>&nbsp; ShareInfo: TShare_Info_502; <br>&nbsp; // New ACL variables. <br>&nbsp; pNewACL : PACL; <br>&nbsp; cbNewACL: DWORD; <br>&nbsp; // Temporary ACE. <br>&nbsp; pTempAce: Pointer; <br>&nbsp; CurrentAceIndex : Cardinal; <br>&nbsp; parm_err: DWORD; <br>begin <br>&nbsp; szDomain := nil; <br>&nbsp; cbDomain := 0; <br>&nbsp; pUserSID := nil; <br>&nbsp; cbUserSID := 0; <br>&nbsp; pNewSD := nil; <br>&nbsp; p_ACL := nil; <br>&nbsp; pNewACL := nil; <br>&nbsp; pTempAce := nil; <br>&nbsp; BufPtr := nil; <br><br>&nbsp; // STEP 1: Get SID for given user. <br>&nbsp; Result := LookupAccountName(nil, PChar(UserName), <br>&nbsp; &nbsp; pUserSID, cbUserSID, szDomain, cbDomain, snuType); <br><br>&nbsp; // API should have failed with insufficient buffer. <br>&nbsp; if (not Result) and (GetLastError &lt;&gt; ERROR_INSUFFICIENT_BUFFER) then <br>&nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; pUserSID := AllocMem(cbUserSID); <br>&nbsp; szDomain := AllocMem(cbDomain); <br>&nbsp; try <br>&nbsp; &nbsp; Result := LookupAccountName(nil, PChar(UserName), <br>&nbsp; &nbsp; &nbsp; &nbsp;pUserSID, cbUserSID, szDomain, cbDomain, snuType); <br><br>&nbsp; &nbsp; if (not Result) then <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; // STEP 2: Get security descriptor (SD) for ShareRes. <br>&nbsp; &nbsp; if (NetShareGetInfo(nil, PWideChar(ShareName), 502, Pointer(BufPtr)) <br>&nbsp; &nbsp; &nbsp; = ERROR_SUCCESS) then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; if not IsValidSecurityDescriptor(BufPtr^.shi502_security_descriptor) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; end <br>&nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; pShareSD := BufPtr^.shi502_security_descriptor; <br>&nbsp; &nbsp; // STEP 3: Initialize new SD. <br>&nbsp; &nbsp; pNewSD := AllocMem(GetSecurityDescriptorLength(pShareSD)); <br><br>&nbsp; &nbsp; if (not InitializeSecurityDescriptor(pNewSD, <br>&nbsp; &nbsp; &nbsp; SECURITY_DESCRIPTOR_REVISION)) then <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; // STEP 4: Get DACL from SD. <br>&nbsp; &nbsp; if (not GetSecurityDescriptorDacl(pShareSD, fDaclPresent, p_ACL, <br>&nbsp; &nbsp; &nbsp; fDaclDefaulted)) then <br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; // <br>&nbsp; &nbsp; // STEP 5: Get size information for DACL. <br>&nbsp; &nbsp; // <br>&nbsp; &nbsp; AclInfo.AceCount := 0; // Assume NULL DACL. <br>&nbsp; &nbsp; AclInfo.AclBytesFree := 0; <br>&nbsp; &nbsp; AclInfo.AclBytesInUse := SizeOf(ACL); <br><br>&nbsp; &nbsp; if (fDaclPresent and Assigned(p_ACL)) then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; if (not GetAclInformation(p_ACL^, @AclInfo, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SizeOf(ACL_SIZE_INFORMATION), AclSizeInformation)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; &nbsp; // STEP 6: Compute size needed for the new ACL. <br>&nbsp; &nbsp; &nbsp; cbNewACL := AclInfo.AclBytesInUse + SizeOf(ACCESS_ALLOWED_ACE) <br>&nbsp; &nbsp; &nbsp; &nbsp; + GetLengthSid(pUserSID) - SizeOf(DWORD); <br><br>&nbsp; &nbsp; &nbsp; // STEP 7: Allocate memory for new ACL. <br>&nbsp; &nbsp; &nbsp; pNewACL := AllocMem(cbNewACL); <br><br>&nbsp; &nbsp; &nbsp; // STEP 8: Initialize the new ACL. <br>&nbsp; &nbsp; &nbsp; if (not InitializeAcl(pNewACL^, cbNewACL, ACL_REVISION2)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; &nbsp; // STEP 9: If DACL is present, copy it to a new DACL. <br>&nbsp; &nbsp; &nbsp; if (fDaclPresent) then <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; // STEP 10: Copy the file's ACEs to the new ACL. <br>&nbsp; &nbsp; &nbsp; &nbsp; if (AclInfo.AceCount &gt; 0) then <br>&nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for CurrentAceIndex := 0 to AclInfo.AceCount - 1 do <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // STEP 11: Get an ACE. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not GetAce(p_ACL^, CurrentAceIndex, pTempAce)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // STEP 12: Add the ACE to the new ACL. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not AddAce(pNewACL^, ACL_REVISION, MAXDWORD, pTempAce, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PACE_HEADER(pTempAce)^.AceSize)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; end; <br><br>&nbsp; &nbsp; &nbsp; // STEP 13: Add the access-allowed ACE to the new DACL. <br>&nbsp; &nbsp; &nbsp; if (not AddAccessAllowedAce(pNewACL^, ACL_REVISION2, dwAccessMask, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pUserSID)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; &nbsp; // STEP 14: Set the new DACL to the new Share SD. <br>&nbsp; &nbsp; &nbsp; if (not SetSecurityDescriptorDacl(pNewSD, True, pNewACL, False)) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; &nbsp; // STEP 15: Set the new SD to the ShareRes. <br>&nbsp; &nbsp; &nbsp; Move(BufPtr^,ShareInfo, SizeOf(ShareInfo)); <br>&nbsp; &nbsp; &nbsp; ShareInfo.shi502_security_descriptor := pNewSD; <br>&nbsp; &nbsp; &nbsp; if not (NetShareSetInfo(nil, PWideChar(ShareName), 502, @ShareInfo, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @parm_err) = ERROR_SUCCESS) then <br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error; <br><br>&nbsp; &nbsp; &nbsp; Result := True; <br>&nbsp; &nbsp; end; <br>&nbsp; finally <br>&nbsp; &nbsp; // STEP 16: Free allocated memory <br>&nbsp; &nbsp; if Assigned(pUserSID) then <br>&nbsp; &nbsp; &nbsp; FreeMem(pUserSID); <br>&nbsp; &nbsp; if Assigned(szDomain) then <br>&nbsp; &nbsp; &nbsp; FreeMem(szDomain); <br>&nbsp; &nbsp; if Assigned(pNewSD) then <br>&nbsp; &nbsp; &nbsp; FreeMem(pNewSD); <br>&nbsp; &nbsp; if Assigned(pNewACL) then <br>&nbsp; &nbsp; &nbsp; FreeMem(pNewACL); <br>&nbsp; &nbsp; if Assigned(BufPtr) then <br>&nbsp; &nbsp; &nbsp; NetApiBufferFree(BufPtr); <br>&nbsp; end; <br>end;
 
thanks<br>不过还是有点问题,请问有没有一些小一点的代码,上面得很不错了,可是我还是不成功呀!<br>谢谢了!
 
谢谢了,各位大哥再来小弟一把吧!
 
upupupuphelphelp
 
我得到的netsharename为?<br>remark为' '<br>人数为1<br>可是这些都不是我设置的效果呀!
 
多人接受答案了。
 
后退
顶部