码迷,mamicode.com
首页 > 编程语言 > 详细

C++ / C# 访问网络共享文件夹

时间:2020-04-25 17:08:24      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:windows   nta   图片   c++   ase   div   命令   spec   contains   

1. C# 

 通过 WebClient 类,使用方法如下: 

 

技术图片
using System;
using System.Net;
using System.IO;

public class Test
{
    public static void Main (string[] args)
    {
        if (args == null || args.Length == 0)
        {
            throw new ApplicationException ("Specify the URI of the resource to retrieve.");
        }
        WebClient client = new WebClient ();

        // Add a user agent header in case the 
        // requested URI contains a query.

        client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

        Stream data = client.OpenRead (args[0]);
        StreamReader reader = new StreamReader (data);
        string s = reader.ReadToEnd ();
        Console.WriteLine (s);
        data.Close ();
        reader.Close ();
    }
}
View Code

 

 

2. C++

 通过 net use 网络映射命令将网络文件夹映射到本地

 (1) 命令行(CMD)输入如下:

 

net use K: \\192.168.90.200\目录 密码 /user:用户名

 

 (2) 代码如下:

 

system("net use K: \\\\192.168.90.200\\目录 密码 /user:用户名");

 

 注:CMD 中可通过 net use ? 查看命令帮助

  

 

C++ / C# 访问网络共享文件夹

标签:windows   nta   图片   c++   ase   div   命令   spec   contains   

原文地址:https://www.cnblogs.com/dhqy/p/12773510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!