查看共享文件夹中是否有足够的磁盘空间来安装
我需要能够在局域网计算机上的共享文件夹中安装程序。
首先,我必须找出计算机上共享哪些文件夹,然后检查是否有足够的磁盘空间来继续安装。
这是我的方法。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的访问被拒绝是因为 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?