| |

VerySource

 Forgot password?
 Register
Search
View: 1018|Reply: 4

In this way, it is possible to establish an IPC $ connection with a machine in the internal network?

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-19 11:30:01
| Show all posts |Read mode
As the question ...
How to achieve it? Hope that Niu Ren can give the code ...
Thank you in advance ~!
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-8-6 14:30:01
| Show all posts
It can be like this:
WinExec('command.com /c net use\\192.168.0.1\ipc$ 123456 /user:administrator',SW_SHOW);
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-8-6 15:15:02
| Show all posts
The above can be simplified to:
WinExec('net use\\192.168.0.1\ipc$ 123456 /user:administrator',SW_SHOW);

Only internal commands need to call command.com or cmd.exe
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-8 04:00:01
| Show all posts
Halo, how to achieve without third-party tools?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-8 08:00:01
| Show all posts
//Establish a remote connection xPath: remote path xNetUser/xNetPassword: user name and password can be specified
function AddNetConnection(xPath, xNetUser, xNetPassword: string): string;
var
  mNetSource: TNetResource;
  mNetUser, mNetPassword: PChar;
  mErrorCode: Cardinal;
begin
  Result :='';
  if Copy(xPath, 1, 2) <> '\\' then Exit; //Non-remote mode, exit

  try
    with mNetSource do
    begin
      dwScope := RESOURCE_GLOBALNET;
      dwType := RESOURCETYPE_ANY;
      dwDisplayType := RESOURCEDISPLAYTYPE_SHARE;
      dwUsage := RESOURCEUSAGE_CONNECTABLE;
      lpLocalName := nil; //You can specify the local drive name here, then map xPath to the local drive, pass nil, and only establish a remote connection with xPath
      lpRemoteName := LPTSTR(xPath);
      lpComment := nil;
      lpProvider := nil;
    end;
    if xNetUser <>'' then
    begin
      mNetUser := LPTSTR(xNetUser);
      mNetPassword := LPTSTR(xNetPassword);
    end
    else
    begin
      mNetUser := nil;
      mNetPassword := nil;
    end;

    mErrorCode := WNetAddConnection2(mNetSource, mNetPassword, mNetUser, CONNECT_UPDATE_PROFILE);
    if mErrorCode <> NO_ERROR then //mapping failed
      Result := Format('An error occurred while establishing a network connection with %s! Error message: %s', [xPath, SysErrorMessage(mErrorCode)]);
  except
    on E: Exception do
      Result := Format('An error occurred while establishing a network connection with %s! Error message: %s', [xPath, E.Message]);
  end;
end;

//mPath if the remote path is passed in, disconnect the network connection with the remote path
//mPath if the local drive name is passed in, the local drive will be disconnected
function CancelNetConnection(xPath: string): string;
var
  mErrorCode: Cardinal;
begin
  Result :='';
  if Copy(xPath, 1, 2) <> '\\' then Exit; //Non-remote mode, exit

  try
    mErrorCode := WNetCancelConnection2(LPTSTR(xPath), CONNECT_UPDATE_PROFILE, True);
    if mErrorCode = NO_ERROR then
      Result := Format('An error occurred while disconnecting from %s! Error message: %s', [xPath, SysErrorMessage(mErrorCode)]);
  except
    on E: Exception do
      Result := Format('An error occurred while disconnecting from %s! Error message: %s', [xPath, E.Message]);
  end;
end;
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list