Board index » delphi » WNetAddConnection2 ???

WNetAddConnection2 ???

My program run an application which is on a server.
I'm using a TExecFile component with the command line :

        \\SERVER\ShareDirectory$\Application.exe

It works fine ! But now i want to put some access restriction to the
application (Username, password...)

How can i do to run this application without redirecting a local device
from a server ? I'm going to use WNetAddConnection2 ... but how does it
work if lpLocalName is NULL ?

 

Re:WNetAddConnection2 ???


Quote
Julien MINET wrote:
> My program run an application which is on a server.
> I'm using a TExecFile component with the command line :

>         \\SERVER\ShareDirectory$\Application.exe

> It works fine ! But now i want to put some access restriction to the
> application (Username, password...)

> How can i do to run this application without redirecting a local device
> from a server ? I'm going to use WNetAddConnection2 ... but how does it
> work if lpLocalName is NULL ?

You can try this:

var
  Username, Password: String;
  NetResource: TNetResource;
begin
  Username := 'User';
  Password := 'password';
  with NetResource do
  begin
    NetResource.dwType := RESOURCETYPE_DISK;
    NetResource.lpLocalName := nil;
    NetResource.lpRemoteName := '\\SERVER\ShareDirectory$';
    NetResource.lpProvider := nil;
  end;
  if WNetAddConnection2(NetResource, PChar(Password), PChar(Username), 0)
<> 0 then
    ShowMessage(SysErrorMessage(GetLastError));
end;

and launch the application with the command line
\\SERVER\ShareDirectory$\Application.exe

Jari

Other Threads