首页
视频
资源
登录
原
.Net 磁盘映射内网远程共享文件夹
114
人阅读
2023/11/16 8:54
总访问:
2263463
评论:
0
收藏:
0
手机
分类:
.net后台框架
 >#.Net 磁盘映射内网远程共享文件夹 [TOC] ```csharp public class WNetHelper { public WNetHelper() { } [DllImport("mpr.dll", EntryPoint = "WNetAddConnection2")] private static extern uint WNetAddConnection2(NetResource lpNetResource, string lpPassword, string lpUsername, uint dwFlags); [DllImport("Mpr.dll", EntryPoint = "WNetCancelConnection2")] private static extern uint WNetCancelConnection2(string lpName, uint dwFlags, bool fForce); [StructLayout(LayoutKind.Sequential)] public class NetResource { public int dwScope; public int dwType; public int dwDisplayType; public int dwUsage; public string lpLocalName; public string lpRemoteName; public string lpComment; public string lpProvider; } /// <summary> /// 为网络共享做本地映射 /// </summary> /// <param name="username">访问用户名(windows系统需要加计算机名,如:comp-1\user-1)</param> /// <param name="password">访问用户密码</param> /// <param name="remoteName">网络共享路径(如:\\192.168.0.9\share)</param> /// <param name="localName">本地映射盘符</param> /// <returns></returns> public static uint WNetAddConnection(string username, string password, string remoteName, string localName) { NetResource netResource = new NetResource(); netResource.dwScope = 2; netResource.dwType = 1; netResource.dwDisplayType = 3; netResource.dwUsage = 1; netResource.lpLocalName = localName; netResource.lpRemoteName = remoteName.TrimEnd('\\'); uint result = WNetAddConnection2(netResource, password, username, 0); return result; } public static uint WNetCancelConnection(string name, uint flags, bool force) { uint nret = WNetCancelConnection2(name, flags, force); return nret; } } ``` tn2>调用方式 ```csharp // 用户名 密码 远程路径 本地盘符 state = WNetHelper.WNetAddConnection(user, pwd, @"\\hznetapp1\hrs-cfa", "P:"); if (state.Equals(0)) { _logger.LogInformation($"创建驱动成功:{state} P:\\Jobs存在不? {Directory.Exists("P:\\Jobs")}"); //创建共享目录的上传路径 if (Directory.Exists("P:\\Jobs")) { _logger.LogInformation("创建驱动成功:" + state.ToString()); } } else { _logger.LogInformation("添加网络驱动器错误,错误号:" + state.ToString()); } ```
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
👈{{preArticle.title}}
👉{{nextArticle.title}}
评价
{{titleitem}}
{{titleitem}}
{{item.content}}
{{titleitem}}
{{titleitem}}
{{item.content}}
尘叶心繁
这一世以无限游戏为使命!
博主信息
排名
6
文章
6
粉丝
16
评论
8
文章类别
.net后台框架
164篇
linux
17篇
linux中cve
1篇
windows中cve
0篇
资源分享
10篇
Win32
3篇
前端
28篇
传说中的c
4篇
Xamarin
9篇
docker
15篇
容器编排
101篇
grpc
4篇
Go
15篇
yaml模板
1篇
理论
2篇
更多
Sqlserver
4篇
云产品
39篇
git
3篇
Unity
1篇
考证
2篇
RabbitMq
23篇
Harbor
1篇
Ansible
8篇
Jenkins
17篇
Vue
1篇
Ids4
18篇
istio
1篇
架构
2篇
网络
7篇
windbg
4篇
AI
17篇
threejs
2篇
人物
1篇
嵌入式
2篇
python
9篇
HuggingFace
8篇
pytorch
1篇
最新文章
最新评价
{{item.articleTitle}}
{{item.blogName}}
:
{{item.content}}
关于我们
ICP备案 :
渝ICP备18016597号-1
网站信息:
2018-2023
TNBLOG.NET
技术交流:
群号656732739
联系我们:
contact@tnblog.net
欢迎加群
欢迎加群交流技术