NetUseAdd() help needed...

freedumb
freedumb used Ask the Experts™
on
I'm currently trying to make my own implementation of the DOS 'net use' command. NetUseAdd() always returns 50, not sure why... thx.

function NetUse(IP, User, Pass, Share, Local: String; Delete: Boolean): Boolean;
var
  ServerPath, SharePath, LocalPath, UserName, Password: array [0..255] of WideChar;
  ui2: USE_INFO_2;
  Ret: Integer;
  Error: DWORD;
  Temp: String;
begin
  if not Delete then begin
    ZeroMemory(@ui2, Sizeof(ui2));
    Temp := '\\' + IP;
    StringToWideChar(Temp, @ServerPath[0], Sizeof(ServerPath));
    Temp := Temp + '\' + Share;
    StringToWideChar(Temp, @SharePath[0], Sizeof(SharePath));
    StringToWideChar(User, @UserName[0], Sizeof(UserName));
    StringToWideChar(Pass, @Password[0], Sizeof(Password));
    StringToWideChar(Local, @LocalPath[0], Sizeof(LocalPath));
    ui2.ui2_local := @LocalPath[0];
    ui2.ui2_remote := @SharePath[0];
    ui2.ui2_password := @Password[0];
    ui2.ui2_username := @UserName[0];
    ui2.ui2_asg_type := USE_WILDCARD;
    ui2.ui2_domainname := 0;
    Ret := NetUseAdd(@ServerPath[0], 1, @ui2, @Error);
    Temp := format('%d - %d - %d', [Ret, Error, GetLastError()]);
    MessageBox(0, PChar(Temp), 'debug', 0);
  end else begin
  end;
end;
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mohammed NasmanSoftware Developer

Commented:
Hello
 
  Don't you use NetUseAdd, it's for win16 only and it replaced with WNetAddConnection2

from win 32 sdk help file:

"The NetUseAdd function is obsolete. It is provided only for compatibility with LAN Manager and 16-bit versions of Windows. Win32-based applications should use the WNetAddConnection2 function."
 
I found this example for create map driver from remote sharing, if you search using Google, you will find much examples for WNetAddConnection2 and Delphi

procedure MapDisk(rem_path, loc_path, user, pwd : PChar; upd : integer);
var
  lpNetResource : TNetResourceA;
  i             : integer;
begin
    lpNetResource.dwScope := RESOURCE_GLOBALNET;
    lpNetResource.dwType := RESOURCETYPE_ANY;
    lpNetResource.dwDisplayType := RESOURCEDISPLAYTYPE_GENERIC;
    lpNetResource.dwUsage := RESOURCEUSAGE_CONNECTABLE;
    lpNetResource.lpLocalName := loc_path;
    lpNetResource.lpRemoteName := rem_path;
    lpNetResource.lpProvider := '';
    i := WNetAddConnection2(lpNetResource, pwd, user, upd);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  MapDisk('\\server\sharing','Z:',nil,nil,0);
end;

Best regards
Mohammed Nasman

Author

Commented:
I know about the WNet* functions, but unfortunately they dont work when my application is running as NT AUTHORITY\SYSTEM for some reason, so i need to use the lower level Net* API's.
Commented:
AFAIK, you don't have network access in the SYSTEM account!

So WNet* is not the problem here.

P.S:

  { The network request is not supported. }
  ERROR_NOT_SUPPORTED = 50;
freedumb:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
kacorretired

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept Madshi's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

If you will get a useful answer to your newer question next time, please accept it after evaluating. By this way the experts will get sooner his expert points for supporting you. If you have question about, please look at  http://www.experts-exchange.com/help.jsp.

kacor
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial