C++ / C# 訪問網絡共享文件夾


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:用戶名");

 

 

 注1:刪除所有映射:net use * /del

 注2:CMD 中可通過 net use ? 查看命令幫助

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM