NetUseAdd() help needed...

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;
freedumbAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed NasmanSoftware DeveloperCommented:
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
0
freedumbAuthor 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.
0
MadshiCommented:
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;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CleanupPingCommented:
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.
0
kacorretiredCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.