I want to list mapped network drives in remote machine using WMI C#.. I am using following code
ConnectionOptions connectionOptions = new ConnectionOptions();
connectionOptions.Username = "myAdminUser";
connectionOptions.Password = "Password";
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope Scope = new ManagementScope(@"\\" + "myClientMachine" + @"\root\cimv2", connectionOptions);
Scope.Connect();
ManagementObjectSearcher win32Drives = new ManagementObjectSearcher(Scope,
new ObjectQuery(@"SELECT Name,UserName FROM Win32_NetworkConnection'"));
foreach (ManagementObject DriveData in win32Drives.Get())
{
string drivePath = (string)DriveData["Name"];
string userName = (string)DriveData["UserName"];
}
I am running this code in my Server Machine with Admin Credentials to get mapped drives from
my Client Machine... this code returns 0 results when I use Admin credentials .. but at the same time when I use my client user credentials it returns mapped drives for the client user.
Here, my question is, is there any way to get all the mapped drives in client Machine for the all the users?