

























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
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。