Goal: to get a list of available shared folder names given a remote server name.
1. I believe this uses the user that is logged into the site. https://www.codeproject.com/Articles/2939/Network-Shares-and-UNC-paths
This was super easy to set up.
2. This is what I wrote if logging in with a specific user:
ManagementPath path = new ManagementPath();
ManagementClass shares = null;
ConnectionOptions co = new ConnectionOptions();
co.Username = "login";
co.Password = "password";
co.Impersonation = ImpersonationLevel.Impersonate;
path.Server = FolderPath; //"devaappwebec01"; // use . for local server, else server name
path.NamespacePath = "root\\CIMV2";
path.RelativePath = @"Win32_Share";
ManagementScope scope = new ManagementScope(path, co); // use (path) for local binds
scope.Connect();
ManagementObjectSearcher worker = new ManagementObjectSearcher(scope,
new ObjectQuery("select Name from win32_share"));
ManagementObjectCollection moc = worker.Get();
No comments:
Post a Comment