查看共享文件夹中是否有足够的磁盘空间来安装

发布于 2024-08-05 05:42:25 字数 1609 浏览 3 评论 0原文

我需要能够在局域网计算机上的共享文件夹中安装程序。

首先,我必须找出计算机上共享哪些文件夹,然后检查是否有足够的磁盘空间来继续安装。

这是我的方法。

public static void FindShares()
    {
        try
        {
            ConnectionOptions options = new ConnectionOptions();
            options.Authentication = AuthenticationLevel.PacketPrivacy;
            options.Impersonation = ImpersonationLevel.Impersonate;
            string path = "\\\\COMPUTERNAME\\root\\cimv2";
            ManagementScope scope = new ManagementScope(path, options);

            scope.Connect();
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Share");

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection queryCollection = searcher.Get();

            foreach (ManagementObject m in queryCollection)
            {
                // Display shared folder information

                Console.WriteLine("Share Name : {0}", m["Name"]);
                Console.WriteLine("Share Path : {0}", m["Path"]);
                Console.WriteLine("AccessMask: {0}", m["AccessMask"]);
                Console.WriteLine("Type: {0}", m["Type"]);
                Console.WriteLine("Status : {0}", m["Status"]);
                Console.WriteLine();
            }

            string line;
            line = Console.ReadLine();
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
    }

当我运行这个时,我收到此错误: 访问被拒绝。 (HRESULT 异常:0x80070005 (E_ACCESSDENIED))

我想我必须以不同的方式设置我的模拟,但我不知道如何。

感谢您的帮助。

I need to be able to install a program in a shared folder on a computer in LAN.

First i must find out which folders are shared on a computer, and then check if there is enough disk space for installation to proceed.

Here is my method.

public static void FindShares()
    {
        try
        {
            ConnectionOptions options = new ConnectionOptions();
            options.Authentication = AuthenticationLevel.PacketPrivacy;
            options.Impersonation = ImpersonationLevel.Impersonate;
            string path = "\\\\COMPUTERNAME\\root\\cimv2";
            ManagementScope scope = new ManagementScope(path, options);

            scope.Connect();
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Share");

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection queryCollection = searcher.Get();

            foreach (ManagementObject m in queryCollection)
            {
                // Display shared folder information

                Console.WriteLine("Share Name : {0}", m["Name"]);
                Console.WriteLine("Share Path : {0}", m["Path"]);
                Console.WriteLine("AccessMask: {0}", m["AccessMask"]);
                Console.WriteLine("Type: {0}", m["Type"]);
                Console.WriteLine("Status : {0}", m["Status"]);
                Console.WriteLine();
            }

            string line;
            line = Console.ReadLine();
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
    }

When i run this i get this error:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I think i must set up my imperonation diferently, but i don't know how.

Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榕城若虚 2024-08-12 05:42:25

您的访问被拒绝是因为 WMI 提供程序在连接到远程计算机时模拟您,而您不是远程计算机上的管理员。

您正在运行此代码的 PC 以及您尝试访问 Windows 域的一部分的 PC 是吗?

您的用户帐户是否直接或间接是目标计算机上本地管理员组的成员?

Your access denied is because the WMI provider is impersonating you when it connects to the remote machine, and you're not an administrator on the remote machine.

Is the PC you are running this code on, and the PC you're trying to hit part of a Windows domain?

Is your user account directly or indirectly a member of the local administrators group on the target computer?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文