Memset (& amp; Ns, 0, sizeof (ns));
Ns. LpLocalName="Z:";//if you don't need to drive, here can be a NULL
Ns. LpRemoteName="\ \ \ \ \ \ machine name Shared name";
Ns. DwType=RESOURCETYPE_DISK;
If (WNetAddConnection2 (& amp; Ns, "Password", "Username", 0)==NO_ERROR)
ShowMessage (" connection is successful, can be accessed online neighbors Shared directory of the machine ");
This is I inquire on the net, there are some problems:
1. The "Password", "Username", "Z:" with variable to hold the words is what kind of?
2. I want to visit is someone else's network Shared directory \ \ 192.168.1.35 password is 123 user name is admin drive symbol should have no?
3. Ns. DwType=RESOURCETYPE_DISK; What is the meaning of this sentence?
I online query WNetAddConnection2 this interface, but there is no complete an example we have, hope you'll give me leave a, if you can take notes,
CodePudding user response:
Is basically to do so.String Username="admin";
String Password="123";
LPNETRESOURCEW lpNetR=new NETRESOURCEW;
String NetConnentName="\ \ \ \ 192.168.1.35 \ \ the IPC $";
LpNetR - & gt; DwScope=RESOURCE_GLOBALNET;
LpNetR - & gt; DwType=RESOURCETYPE_DISK;
LpNetR - & gt; DwDisplayType=RESOURCEDISPLAYTYPE_SHARE;
LpNetR - & gt; DwUsage=RESOURCEUSAGE_CONNECTABLE;
LpNetR - & gt; LpLocalName="";
LpNetR - & gt; LpRemoteName=NetConnentName. C_str ();
LpNetR - & gt; LpProvider="";
WNetCancelConnection2W (lpNetR - & gt; LpRemoteName dwFlages, true);
If (WNetAddConnection2 (lpNetR, Password. C_str (),
The Username. C_str (), dwFlages)==NO_ERROR)
{
//the IPC connection success
WNetCancelConnection2 (lpNetR - & gt; LpRemoteName dwFlages, true);
//ready to connect to the C $
NetConnentName="\ \ \ \ 192.168.1.35 \ \ C $";
LpNetR - & gt; LpLocalName="Z:";
LpNetR - & gt; LpRemoteName=NetConnentName. C_str ();
If (WNetAddConnection2 (lpNetR, Password. C_str (), Username, c_str (), dwFlages)==NO_ERROR)
{
//connection sharing local path to success is Z:
}
}
CodePudding user response:
Very powerful, very practicalCodePudding user response:
The landlord will not stick?