如何在Delphi 10.1 Berlin中安全地访问“共享文件夹”?

问题描述 投票:0回答:1

我们的应用程序使用Shared Folder进行导入或导出数据操作。许多工作站从应用程序访问这些共享位置。

我们需要保护共享文件夹以及从应用程序访问此共享文件夹的过程。

我们尝试编写一个示例应用程序,尝试使用Network Service帐户连接到共享文件夹,但我们没有这样做。同样与Standard Domain User合作。

代码片段:

Result := LogonUser(PChar(User), PChar(Domain),
    PChar(Password), LogonType, LogonProvider, TokenHandle);

  if Result then
  begin
    Result := ImpersonateLoggedOnUser(TokenHandle);
  end;

任何人都有关于保护此工作流程的任何其他建议?

更新:我尝试过使用Network Service帐户的可能性,但这也失败了。

>runas /user:"NT AUTHORITY\Network Service" "C:\Windows\system32\notepad.exe"
Enter the password for NT AUTHORITY\Network Service:
RUNAS ERROR: Unable to acquire user password
security delphi restriction delphi-10.1-berlin shared-folders
1个回答
0
投票

你需要使用windows api函数WNetAddConnection2来添加共享。请参阅链接页面底部的示例代码。添加后,您可以访问该共享文件夹。

访问WNetCancelConnection2后不要忘记删除连接。

© www.soinside.com 2019 - 2024. All rights reserved.