c# - Querying access to a UNC path on a remote machine via WMI -
i want find out if remote host has r/w access network share. start out wanted see if query target host's ability query unc path info, ala
var query = string.format("select * cim_directory name = '{0}'", path); this works fine local files, e.g.
var path = @"c:\\windows"; however, can't figure out appropriate way of querying unc path (e.g. \\foo\bar). query returns blank set. saw related question executing remote files , solution 1 ended beingness psexec. hoping ideally solve problem exclusively using wmi without having rely on 3rd party execs, or uploading own tool remote host.
cheers
here's little usage sample of trying right (var values taken out):
using system; using system.linq; using system.management; namespace netie { class programme { static void main() { var connection = new connectionoptions { username = "user", password = "pass", authorization = "domain", impersonation = impersonationlevel.impersonate, enableprivileges = true }; var scope = new managementscope("\\\\remote\\root\\cimv2", connection); scope.connect(); var path = @"\\\\foo\\bar\\"; var querystring = string.format("select * cim_directory name = '{0}'", path); seek { var query = new objectquery(querystring); var searcher = new managementobjectsearcher(scope, query); foreach (var queryobj in searcher.get().cast<managementobject>()) { console.writeline("number of properties: {0}", queryobj.properties.count); foreach (var prop in queryobj.properties) { console.writeline("{0}: {1}", prop.name, prop.value); } console.writeline(); } } grab (exception e) { console.writeline(e); } console.readline(); } } }
so looks impossible wmi locks out of network access security reasons. looks best bet winrm or psexec one-offs. can potentially enable winrm through wmi if that's path of access, imagine ability can blocked grouping policies. 3rd alternative write own windows service respond requests , installing through wmi if have access.
in short: reply question no. utilize winrm, psexec, or custom win-service solution.
c# wmi unc wql
No comments:
Post a Comment