1
public class NetWork
2
{
3
[StructLayout(LayoutKind.Sequential)]
4
public class NetResource
5
{
6
Create net use sturcture
69![]()
70
public RESOURCE_SCOPE dwScope;
71
public RESOURCE_TYPE dwType;
72
public RESOURCE_DISPLAYTYPE dwDisplayType;
73
public RESOURCE_USAGE dwUsage;
74
public string LocalName;
75
public string RemoteName;
76
public string Comment;
77
public string Provider;
78
}
79![]()
80
///
81
/// mpr.dll
82
///
83
[DllImport("mpr.dll", CharSet = CharSet.Ansi)]
84
public static extern int WNetAddConnection2A(NetResource netResource,
85
String password,
86
String Username,
87
int Flag);
88![]()
89![]()
90
///
91
/// Create net use.
92
///
93
public int CreateNetConnection(string RemoteName, string Password, string UserName)
94
{
95
NetResource myNetResource = new NetResource();
96
myNetResource.dwScope = NetResource.RESOURCE_SCOPE.RESOURCE_GLOBALNET;
97
myNetResource.dwType = NetResource.RESOURCE_TYPE.RESOURCETYPE_ANY;
98
myNetResource.dwDisplayType = NetResource.RESOURCE_DISPLAYTYPE.RESOURCEDISPLAYTYPE_GENERIC;
99
myNetResource.dwUsage = NetResource.RESOURCE_USAGE.RESOURCEUSAGE_CONNECTABLE;
100
//myNetResource.LocalName = "Z:"; // Mapping to local dirver
101
myNetResource.RemoteName = RemoteName; // Remote host IP or host name.
102
myNetResource.Provider = null;
103
return WNetAddConnection2A(myNetResource, Password, UserName, 0);
104
}
105![]()
106
}
public class NetWork2
{3
[StructLayout(LayoutKind.Sequential)]4
public class NetResource5
{6
Create net use sturcture69

70
public RESOURCE_SCOPE dwScope;71
public RESOURCE_TYPE dwType;72
public RESOURCE_DISPLAYTYPE dwDisplayType;73
public RESOURCE_USAGE dwUsage;74
public string LocalName;75
public string RemoteName;76
public string Comment;77
public string Provider;78
}79

80
/// 81
/// mpr.dll 82
/// 83
[DllImport("mpr.dll", CharSet = CharSet.Ansi)]84
public static extern int WNetAddConnection2A(NetResource netResource,85
String password,86
String Username,87
int Flag);88

89

90
/// 91
/// Create net use. 92
/// 93
public int CreateNetConnection(string RemoteName, string Password, string UserName)94
{95
NetResource myNetResource = new NetResource();96
myNetResource.dwScope = NetResource.RESOURCE_SCOPE.RESOURCE_GLOBALNET;97
myNetResource.dwType = NetResource.RESOURCE_TYPE.RESOURCETYPE_ANY;98
myNetResource.dwDisplayType = NetResource.RESOURCE_DISPLAYTYPE.RESOURCEDISPLAYTYPE_GENERIC;99
myNetResource.dwUsage = NetResource.RESOURCE_USAGE.RESOURCEUSAGE_CONNECTABLE;100
//myNetResource.LocalName = "Z:"; // Mapping to local dirver 101
myNetResource.RemoteName = RemoteName; // Remote host IP or host name. 102
myNetResource.Provider = null;103
return WNetAddConnection2A(myNetResource, Password, UserName, 0);104
}105

106
}

浙公网安备 33010602011771号