使用Delphi通过网络连接到受密码保护的共享文件夹

use*_*015 2 delphi directory networking shared network-programming

我有一个多用户Delphi程序,需要通过网络共享文件夹来存储数据.我希望程序更改该文件夹中的文件,但不是普通用户(可以看到此文件夹)或网络病毒...

我想用密码保护这个文件夹(Windows 7),但我需要通过我的程序编写新文件或编辑现有文件,我不知道如何做到这一点.

简而言之,我需要通过这样的代码连接和断开共享文件夹

ConnectToFolder(\\myServerMachine\mySharedfolder username:me password:myPassword);
disConnectToFolder(\\myServerMachine\mySharedfolder username:me password:myPassword);
Run Code Online (Sandbox Code Playgroud)

这可能吗?

And*_*y_D 5

像这样的东西可能会成功

function ConnectShare(Drive, RemotePath, UserName, Password : String):Integer;
var
  NRW : TNetResource;
begin
  with NRW do
  begin
    dwType := RESOURCETYPE_ANY;
    if Drive <> '' then
      lpLocalName := PChar(Drive)
    else
      lpLocalName := nil;
    lpRemoteName := PChar(RemotePath);
    lpProvider := '';
  end;
  Result := WNetAddConnection2(NRW, PChar(Password), PChar(UserName), 0);
end;

function DisconnectShare(Drive : String):Integer;
begin
  Result := WNetCancelConnection2(PChar(Drive), 0, false);
end;
Run Code Online (Sandbox Code Playgroud)