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.