日期:2014-05-18 浏览次数:21059 次
[DllImport("mpr.dll", EntryPoint = "WNetAddConnection2")]
public static extern uint WNetAddConnection2(
[In] NETRESOURCE lpNetResource,
string lpPassword,
string lpUsername,
uint dwFlags);
[DllImport("Mpr.dll")]
public static extern uint WNetCancelConnection2(
string lpName,
uint dwFlags,
bool fForce);
[StructLayout(LayoutKind.Sequential)]
public class NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDispalyType;
public int dwUsage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
}
private Parent _parent;
public Parent parent
{
get { return _parent; }
set { _parent = value; }
}
static void Main()
{
Tester t = new Tester();
NETRESOURCE myNetResource = new NETRESOURCE();
myNetResource.dwScope = 2;
myNetResource.dwType = 1;
myNetResource.dwDispalyType = 3;
myNetResource.dwUsage = 1;
myNetResource.LocalName = "L:";
myNetResource.RemoteName = "\\\\192.168.1.134\\abc";
uint nret = WNetAddConnection2(myNetResource,"" ,"" , 0);
Console.WriteLine(nret);
}