freedumb
asked on
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;
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;
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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 https://www.experts-exchange.com/help.jsp.
kacor
EE Cleanup Volunteer
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 https://www.experts-exchange.com/help.jsp.
kacor
EE Cleanup Volunteer
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.dwDisplayTyp
lpNetResource.dwUsage := RESOURCEUSAGE_CONNECTABLE;
lpNetResource.lpLocalName := loc_path;
lpNetResource.lpRemoteName
lpNetResource.lpProvider := '';
i := WNetAddConnection2(lpNetRe
end;
procedure TForm1.Button1Click(Sender
begin
MapDisk('\\server\sharing'
end;
Best regards
Mohammed Nasman