通过WMI查询远程机器上访问UNC路径 [英] Querying access to a UNC path on a remote machine via WMI

查看:158
本文介绍了通过WMI查询远程机器上访问UNC路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找出如果远程主机具有网络共享R / W访问。要开始了,我想看看我是否能查询目标主机对查询信息的UNC路径的能力,ALA

  VAR查询=的String.Format(SELECT * FROM CIM_Directory其中名称='{0}',路径); 

这对于本地文件,如:



正常工作

  VAR路径= @C:\\Windows 



不过,我想不通查询UNC路径的适当方式(如\\\ \\foo\bar)。查询总是返回一个空集。我看到了有关执行远程文件和一个结束了PSEXEC解决一个相关的问题。我希望最好解决完全使用WMI这个问题,而不必依赖于第三方的高管,或上传自己的工具到远程主机。



干杯



这里是什么,我试图做的,现在(取出来的VAR值的一点用法示例):

 使用系统; 
使用System.Linq的;
使用System.Management;

命名空间netie
{
类节目
{
静态无效的主要()
{
VAR连接=新ConnectionOptions
{
=用户名用户,
密码=通行证,
管理局=域,
模拟= ImpersonationLevel.Impersonate,
EnablePrivileges =真正的
};

变种范围=新的管理范围(\\\\remote\\root\\CIMV2连接);
scope.Connect();

VAR路径= @\\\\foo\\bar\\
变种的queryString =的String.Format(SELECT * FROM CIM_Directory其中名称='{0}',路径);

{
VAR的查询=新的ObjectQuery(的queryString);
变种搜索=新ManagementObjectSearcher(范围,查询);

的foreach(在searcher.Get VAR queryObj()演员LT;的ManagementObject>()。)
{
Console.WriteLine(物业数目:{0},queryObj .Properties.Count);
的foreach(在queryObj.Properties VAR道具)
{
Console.WriteLine({0}:{1},prop.Name,prop.Value);
}
Console.WriteLine();
}
}
赶上(例外五)
{
Console.WriteLine(E);
}
到Console.ReadLine();
}
}
}


解决方案

所以看起来这基本上是不可能的,因为WMI锁定你出去出于安全原因,网络访问。看起来像你最好的赌注是WinRM的或PSEXEC一个权衡。您可以通过潜在WMI启用WinRM的,如果这是你唯一的访问路径,但我想象能力可以通过组策略来阻止。 。第三个选项是编写自己的Windows服务,将响应请求并安装通过WMI,如果你有访问



在短期:回答我的问题是,第一个使用WinRM的,PSEXEC或定制双赢的服务解决方案。


I want to find out if the remote host has r/w access to a network share. To start out I wanted to see if I could query the target host's ability to query the UNC path for info, ala

var query = string.Format("select * from CIM_Directory where name = '{0}'", path);

This works fine for local files, e.g.

var path = @"c:\\Windows";

However, I can't figure out an appropriate way of querying a UNC path (e.g. \\foo\bar). The query always returns a blank set. I saw a related question about executing remote files and the solution for that one ended up being PsExec. I was hoping to ideally solve this problem entirely using WMI without having to rely on 3rd party execs, or uploading my own tool to the remote host.

Cheers

Here's a little usage sample of what I am trying to do right now (var values taken out):

using System;
using System.Linq;
using System.Management;

namespace netie
{
    class Program
    {
        static void Main()
        {
            var connection = new ConnectionOptions
            {
                Username = "user",
                Password = "pass",
                Authority = "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 * from CIM_Directory where name = '{0}'", path);
            try
            {
                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();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
    }
}

解决方案

So it looks like this is basically impossible as WMI locks you out of network access for security reasons. Looks like your best bet is WinRM or PsExec for one-offs. You can potentially enable WinRM through WMI if that's your only path of access, but I imagine that ability can be blocked by group policies. The third option is to write your own Windows Service that will respond to requests and installing that through WMI if you have the access.

In short: the answer to my question is a No. Use WinRm, PsExec, or a custom win-service solution.

这篇关于通过WMI查询远程机器上访问UNC路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆